Exception: Exception
- Defined in:
- lib/squash/ruby/exception_additions.rb
Overview
Reopens the ‘Exception` class to add a convenient way of appending user data to an exception at the time of the raise.
Class Method Summary collapse
-
.new(message, user_data = {}) ⇒ Exception
Creates a new exception instance, optionally with user data.
Instance Method Summary collapse
-
#user_data(data) ⇒ Exception
Annotates this exception with user data.
Class Method Details
.new(message, user_data = {}) ⇒ Exception
31 32 33 34 35 36 37 38 |
# File 'lib/squash/ruby/exception_additions.rb', line 31 def self.new(*args) user_data = if args.last.is_a?(Hash) args.pop else {} end super(*args).user_data(user_data) end |
Instance Method Details
#user_data(data) ⇒ Exception
Annotates this exception with user data. Merges in any new data with existing user data.
47 48 49 50 51 52 53 |
# File 'lib/squash/ruby/exception_additions.rb', line 47 def user_data(data) Squash::Ruby.check_user_data data data.each do |ivar, value| instance_variable_set :"@#{ivar}", value end self end |