begin
raise NoMemoryError, "NO MEMORY !!!"
rescue
puts "rescued"
end
=> rescued
But for example it does not trap ScriptError exceptions. So which
exact exception classes does "rescue" trap? is it docummented
somewhere? Unfortunately I am not able to find in Ruby sources where
the definition of "rescue" is.
Hi, using Ruby 1.9 I've realized that "rescue" traps more than
StandardError exceptions, for example NoMemoryError:
Not for me it doesn't.
irb
1.9.3p125 :001 > NoMemoryError.ancestors
=> [NoMemoryError, Exception, Object, Kernel, BasicObject]
1.9.3p125 :002 >
1.9.3p125 :003 > begin
1.9.3p125 :004 > raise NoMemoryError, "NO MEMORY !!!"
1.9.3p125 :005?> rescue
1.9.3p125 :006?> puts "rescued"
1.9.3p125 :007?> end
NoMemoryError: NO MEMORY !!!
from (irb):4
from /Users/henry/.rvm/rubies/ruby-1.9.3-p125/bin/irb:16:in `<main>'
1.9.3p125 :008 >
But for example it does not trap ScriptError exceptions. So which
exact exception classes does "rescue" trap? is it docummented
somewhere? Unfortunately I am not able to find in Ruby sources where
the definition of "rescue" is.
According to the "IPA Ruby Standardization WG Draft August 25, 2010"
(page 97)
11.5.2.5 The begin expression
Semantics
c.2
"If the exception-class-list is omitted in the rescue-clause, and if E
is an instance of the class StandardError, the rescue-clause handles E."
If any Ruby interpreter handles any exception that is not a sub-class of
StandardError in a rescue-clause (no exception-class-list), then it is
in error.
Hi, using Ruby 1.9 I've realized that "rescue" traps more than
StandardError exceptions, for example NoMemoryError:
Not for me it doesn't.
My fault, sorry, I did a wrong code.
But for example it does not trap ScriptError exceptions. So which
exact exception classes does "rescue" trap? is it docummented
somewhere? Unfortunately I am not able to find in Ruby sources where
the definition of "rescue" is.
According to the "IPA Ruby Standardization WG Draft August 25, 2010"
(page 97)
11.5.2.5 The begin expression
Semantics
c.2
"If the exception-class-list is omitted in the rescue-clause, and if E
is an instance of the class StandardError, the rescue-clause handles E."
If any Ruby interpreter handles any exception that is not a sub-class of
StandardError in a rescue-clause (no exception-class-list), then it is
in error.