Skip to content

Instantly share code, notes, and snippets.

@philmill
Last active February 5, 2016 21:39
Show Gist options
  • Save philmill/99a2e2d727e1e801dbf1 to your computer and use it in GitHub Desktop.
Save philmill/99a2e2d727e1e801dbf1 to your computer and use it in GitHub Desktop.
Ruby: Begin Rescue Ensure
begin
# something which might raise an exception
rescue SomeExceptionClass => some_variable
# code that deals with some exception
rescue SomeOtherException => some_other_variable
# code that deals with some other exception
else
# code that runs only if *no* exception was raised
ensure
# ensure that this code always runs, no matter what
end
# http://stackoverflow.com/a/2192010
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment