tags:

views:

42

answers:

1

Which exceptions are you catching when you don't specify an exception class like this:

begin
  # do something
rescue
  puts "Exception!"
end
+5  A: 

According to my copy of Programming Ruby 1.9,

A rescue clause with no parameter is treated as if it had a parameter of StandardError.

And here's the documentation from ruby-doc.org:

By default, rescue only intercepts StandardError and its descendants, but you can specify which exceptions you want handled, as arguments. (This technique does not work when rescue is in statement-modifier position.)

The Why Not Wiki has the Exception hierarchy available if you need to reference it.

As a quick reference, the Exception classes that are not derived from StandardError are:

  • fatal
  • NoMemoryError
  • ScriptError
  • SignalException
  • SystemExit
  • SystemStackError
Mark Rushakoff