The match will succeed if the exception named in the rescue clause is the same as the type of the currently thrown exception or is a superclass of that exception.
Ruby raise exception with arguments.
In a nutshell every custom ruby exception should extend standarderror rather than the exception class the reason for this is outlined in exception handling in ruby with this in mind the simplest custom exception class that we can define will look something like this.
First 4 5 raises the exception.
Wrong number of arguments given 2 expected 1 ex.
While some languages only use exceptions for truly exceptional circumstances like run time errors ruby uses exceptions for a wide variety of errors and unexpected results.
To get the most out of your own applications and to fully manage any and all ruby exceptions check out the airbrake ruby exception handling tool offering real time alerts and instantaneous insight into what went wrong with your ruby code including integrated support for a variety of popular ruby gems and frameworks.
First 4 raises the exception.
Passing the wrong number of arguments 1 2 3.
In ruby like in most languages an exception is a way to convey that something went wrong.
Passing an argument that is not acceptable.
The match will succeed if the exception named in the rescue clause is the same as the type of the currently thrown exception or is a superclass of that exception.
Raised when the arguments are wrong and there isn t a more specific exception class.
For each rescue clause in the begin block ruby compares the raised exception against each of the parameters in turn.