instance method
Exception#exception
(?self) -> self
(::string | ::_ToS message) -> self
exception(message = nil) → self or new_exception
error.c
View on GitHub ↗
static VALUE
exc_exception(int argc, VALUE *argv, VALUE self)
{
VALUE exc;
argc = rb_check_arity(argc, 0, 1);
if (argc == 0) return self;
if (argc == 1 && self == argv[0]) return self;
exc = rb_obj_clone(self);
rb_ivar_set(exc, id_mesg, argv[0]);
return exc;
}
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
See also
.exception
#detailed_message
#full_message
#cause
also in
4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0