Skip to content

Instantly share code, notes, and snippets.

@gouravtiwari
Created July 3, 2014 08:28
Show Gist options
  • Save gouravtiwari/21af37fa92d352cf0b80 to your computer and use it in GitHub Desktop.
Save gouravtiwari/21af37fa92d352cf0b80 to your computer and use it in GitHub Desktop.
Exception examples in Ruby
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