Created
January 27, 2020 17:58
-
-
Save zaagan/e3d00a8c539e0fbc443ac1830b1eb54b to your computer and use it in GitHub Desktop.
Ruby Basics - Exception Handling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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