Skip to content

Instantly share code, notes, and snippets.

@jesscanady
Created January 18, 2012 19:35
Show Gist options
  • Save jesscanady/1635084 to your computer and use it in GitHub Desktop.
Save jesscanady/1635084 to your computer and use it in GitHub Desktop.
Custom errors that extend "Exception" don't get caught by bare rescue statements.
#
# Custom error classes that extend Exception don't get caught by catch-all/bare rescue statements.
#
class ExtendsStandardError < StandardError; end
class ExtendsException < Exception; end
begin
raise ExtendsStandardError, "Burn."
rescue
puts "ExtendsStandardError caught."
end
begin
raise ExtendsException, "Burn."
rescue
puts "ExtendsException caught."
end
puts "Both caught."
# outputs:
#
# ExtendsStandardError caught.
# exception_test.rb:13: Burn. (ExtendsException)
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment