« Back to Index

Custom Ruby Error Handling

View original Gist on GitHub

Custom Ruby Error Handling.rb

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