class method
Exception.exception
(?::string | ::_ToS msg) -> instance
exception(message = nil) → self or new_exception
error.c
View on GitHub ↗
Returns an exception object of the same class as self; useful for creating a similar exception, but with a different message.
With message nil, returns self:
Example
x0 = StandardError.new('Boom') # => #<StandardError: Boom> x1 = x0.exception # => #<StandardError: Boom> x0.__id__ == x1.__id__ # => true
With string-convertible object message (even the same as the original message), returns a new exception object whose class is the same as self, and whose message is the given message:
Example
x1 = x0.exception('Boom') # => #<StandardError: Boom> x0..equal?(x1) # => false