2

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

begin
  # do something
rescue
  puts "Exception!"
end
readonly
  • 343,444
  • 107
  • 203
  • 205

1 Answers1

7

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
  • 249,864
  • 45
  • 407
  • 398
  • Note that there are [several more standard exceptions inheriting from the above](http://stackoverflow.com/questions/5118745/is-systemexit-a-special-kind-of-exception/5120214#5120214) that are, therefor, also not covered. Most commonly: `LoadError`, `NotImplementedError`, `SyntaxError`. – Phrogz Feb 28 '11 at 15:55