Skip to content

Instantly share code, notes, and snippets.

@zaagan
Created January 27, 2020 17:58
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 zaagan/e3d00a8c539e0fbc443ac1830b1eb54b to your computer and use it in GitHub Desktop.
Save zaagan/e3d00a8c539e0fbc443ac1830b1eb54b to your computer and use it in GitHub Desktop.
Ruby Basics - Exception Handling
# Example 1
begin
x = 5 / 0
rescue
puts "Ohh no !!!"
ensure
puts "This will always execute"
end
# Example 2
begin
x = 5 / 0
rescue ZeroDivisionError
puts "Did you just divid by a zero ??"
end
# Example 3
begin
x = 5 / 0
rescue Exception => ex
puts ex.message
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment