Skip to content

Instantly share code, notes, and snippets.

Created September 6, 2016 09:08
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 anonymous/bc8d25c2d5f2e4dca84b8ad3fc943a84 to your computer and use it in GitHub Desktop.
Save anonymous/bc8d25c2d5f2e4dca84b8ad3fc943a84 to your computer and use it in GitHub Desktop.
exception handling
class MyExc < StandardError;end
class MyExc1 < MyExc;end
class Foo
def initialize params={}
params.each {
|k,v|
instance_variable_set "@#{k}",v
}
end
def yay; raise MyExc1, "what";end
end
f = Foo.new(a: 10, b: 2); p f
begin
f.yay
rescue MyExc => e
p e.message, e.class
end
'
#<Foo:0x00000000dab740 @a=10, @b=2>
"what"
MyExc1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment