Created
January 18, 2012 19:35
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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