Method: Exception#cause
- Defined in:
- error.c
#cause ⇒ Exception?
Returns the previous value of global variable $!
, which may be nil
(see Global Variables):
begin
raise('Boom 0')
rescue => x0
puts "Exception: #{x0}; $!: #{$!}; cause: #{x0.cause.inspect}."
begin
raise('Boom 1')
rescue => x1
puts "Exception: #{x1}; $!: #{$!}; cause: #{x1.cause}."
begin
raise('Boom 2')
rescue => x2
puts "Exception: #{x2}; $!: #{$!}; cause: #{x2.cause}."
end
end
end
Output:
Exception: Boom 0; $!: Boom 0; cause: nil.
Exception: Boom 1; $!: Boom 1; cause: Boom 0.
Exception: Boom 2; $!: Boom 2; cause: Boom 1.
2160 2161 2162 2163 2164 |
# File 'error.c', line 2160
static VALUE
exc_cause(VALUE exc)
{
return rb_attr_get(exc, id_cause);
}
|