Created
April 8, 2014 14:42
-
-
Save Integralist/10135411 to your computer and use it in GitHub Desktop.
Custom Ruby Error 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 MyCustomError < StandardError | |
attr_reader :object | |
def initialize(object) | |
@object = object | |
end | |
end | |
begin | |
raise MyCustomError.new("an object"), "a message" | |
rescue Exception => e | |
puts e.message # => "a message" | |
puts e.object # => "an object" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use it like so: