Created
July 3, 2014 08:28
-
-
Save gouravtiwari/21af37fa92d352cf0b80 to your computer and use it in GitHub Desktop.
Exception examples in Ruby
This file contains hidden or 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
class MyError < StandardError | |
attr_accessor :name | |
def initialize(name) | |
@name = name | |
end | |
end | |
def test(value) | |
trial = 0 | |
trial += 1 | |
50/value | |
value.to_s | |
raise MyError.new('Jignesh') | |
rescue MyError => m | |
p m.inspect | |
m.name | |
rescue ZeroDivisionError => e | |
p e.inspect | |
p e.backtrace.join('\n') | |
value +=1 | |
print trial | |
retry | |
rescue Exception => e | |
p e.inspect | |
"I go it" | |
else | |
"I am good" | |
ensure | |
p "Kiprosh" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment