class Exception
Reopens the `Exception` class to add a convenient way of appending user data to an exception at the time of the raise.
@example
raise ArgumentError.new("value must be a number", value: value) unless value.kind_of?(Fixnum)
Public Class Methods
new(*args)
click to toggle source
@overload new(message, user_data
={})
Creates a new exception instance, optionally with user data. @param [String] message The exception message. @param [Hash] user_data Additional data to report to Squash about the exception. @return [Exception] The initialized exception. @raise [ArgumentError] If `data` contains the keys `mesg` or `bt`.
Calls superclass method
# 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
Public Instance Methods
user_data(data)
click to toggle source
Annotates this exception with user data. Merges in any new data with existing user data.
@param [Hash] data The user data to add. @return [Exception] The receiver. @raise [ArgumentError] If `data` contains the keys `mesg` or `bt`.
# 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