« Back to Index

Basic Ruby exception and error handling

View original Gist on GitHub

Basic Ruby exception and error handling.rb

class SomeCustomException < StandardError
  def initialize(msg = "Some default error message")
    super
  end
end

def this_will_fail
  raise SomeCustomException.new("This will be the error message")
rescue SomeCustomException => e
  p e.message # => This will be the error message
end