Created
October 21, 2010 23:15
-
-
Save andrewvc/639577 to your computer and use it in GitHub Desktop.
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
#BAD: Rescuing a very generic error class like StandardError or ArgumentError without a logger statement. makes it harder to debug code #If someone modifies Foo#baz later, they'll be wondering why their errors aren't being caught. | |
begin | |
Foo.calculate_baz | |
rescue StandardError => e | |
return 5 | |
end | |
#BAD: Never rescue Exception, use StandardError instead. Exception catches some signals as Exceptions. | |
begin | |
... | |
rescue Exception => e | |
... | |
end | |
#GOOD: Rescuing StandardError is fine, so long as its logged | |
begin | |
... | |
rescue StandardError => e | |
logger.warn("Could not frozzle foo: #{e.message}\n{e.backtrace.join("\n")}") | |
end | |
#GOOD: Silence only specific error classes | |
begin | |
... | |
rescue Foo::TheMonkeysGotOut #False alarm | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment