Created
March 28, 2013 18:50
-
-
Save amiel/5265795 to your computer and use it in GitHub Desktop.
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 MyException < StandardError | |
attr_reader :arbitrary_value | |
def initialize(message, arbitrary_value) | |
super(message) | |
@arbitrary_value = arbitrary_value | |
end | |
end | |
e = (raise MyException.new('this is the regular message', 'my value') rescue $!) | |
# this is a shortcut for: | |
begin | |
raise MyException.new('this is the regular message', 'my value') | |
rescue MyException => e | |
e.inspect #=> #<#<Class:0x007ff06943f808>::MyException: this is the regular message> | |
e.arbitrary_value #=> "my value" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment