Skip to content

Instantly share code, notes, and snippets.

@andrewvc
Created October 21, 2010 23:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewvc/639577 to your computer and use it in GitHub Desktop.
Save andrewvc/639577 to your computer and use it in GitHub Desktop.
#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