Answer by Chad M for Ruby custom error classes: inheritance of the message...
Given what the ruby core documentation of Exception, from which all other errors inherit, states about #messageReturns the result of invoking exception.to_s. Normally this returns the exception’s...
View ArticleAnswer by Huliax for Ruby custom error classes: inheritance of the message...
I wanted to do something similar. I wanted to pass an object to #new and have the message set based on some processing of the passed object. The following works.class FooError < StandardError...
View ArticleAnswer by Stefan for Ruby custom error classes: inheritance of the message...
raise already sets the message so you don't have to pass it to the constructor:class MyCustomError < StandardError attr_reader :object def initialize(object) @object = object endendbegin raise...
View ArticleAnswer by sawa for Ruby custom error classes: inheritance of the message...
Your idea is right, but the way you call it is wrong. It should beraise MyCustomError.new(an_object, "A message")
View ArticleRuby custom error classes: inheritance of the message attribute
I can't seem to find much information about custom exception classes.What I do knowYou can declare your custom error class and let it inherit from StandardError, so it can be rescued:class...
View Article