Skip to content

Instantly share code, notes, and snippets.

@Integralist
Created April 8, 2014 14:42
Show Gist options
  • Save Integralist/10135411 to your computer and use it in GitHub Desktop.
Save Integralist/10135411 to your computer and use it in GitHub Desktop.
Custom Ruby Error Handling
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
@Integralist
Copy link
Author

module Mozart
  module Composition
    module Error
      class FailedComponentRequest < StandardError
        def initialize(url)
          super "The service was unable to be reached with the following #{url}"
        end
      end
    end
  end
end

Use it like so:

fail ::Composition::Error::FailedComponentRequest.new(url)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment