Skip to content

Instantly share code, notes, and snippets.

@fantgeass
Created December 2, 2014 15:30
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 fantgeass/3399cddac58eef3213eb to your computer and use it in GitHub Desktop.
Save fantgeass/3399cddac58eef3213eb to your computer and use it in GitHub Desktop.
how-to: exceptions in ruby
def foo
yield
rescue
puts "Only on error"
else
puts "Only on success"
ensure
puts "Always executed"
end
foo{ raise "Error" }
puts "---"
foo{ "No error" }
# Output:
# Only on error
# Always executed
# ---
# Only on success
# Always executed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment