Skip to content

Instantly share code, notes, and snippets.

@amiel
Last active August 29, 2015 13:56
Show Gist options
  • Save amiel/9126937 to your computer and use it in GitHub Desktop.
Save amiel/9126937 to your computer and use it in GitHub Desktop.
Ignoring stupid errors
SMRT_ERRORS = [ServiceClaimsIsATeapot]
def ignore_stupid_errors(error_block = ->(*){})
yield
rescue *SMRT_ERRORS => e
error_block.call e
end
class SomeClass
def do_something
ignore_stupid_errors do
check_the_teapot
end
end
def with_handle_error
ignore_stupid_errors(method(:error_handler)) do
check_the_teapot
end
end
def error_handler(error)
puts "Oops #{error.inspect}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment