Skip to content

Instantly share code, notes, and snippets.

@amiel
Created March 28, 2013 18:50
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 amiel/5265795 to your computer and use it in GitHub Desktop.
Save amiel/5265795 to your computer and use it in GitHub Desktop.
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