-
-
Save anonymous/bc8d25c2d5f2e4dca84b8ad3fc943a84 to your computer and use it in GitHub Desktop.
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
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