From: Henry Maddocks Date: 2012-05-17T07:26:39+09:00 Subject: Re: Which exception classes does "rescue" trap? On 17/05/2012, at 9:59 AM, Iņaki Baz Castillo wrote: > 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 `
' 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. Google is your friend... http://jpablobr.com/past/ruby-s-exception-hierarchy Rescuing an Exception class will also rescue it's sub-classes. This doesn't work work for modules though, which would be really handy. Henry