On 13 Juli, 14:07, Abder-Rahman A. [email protected]
In the following sentence: The raise method is from the Kernel module.
By default, raise creates an exception of the RuntimeError class. From:http://rubylearning.com/satishtalim/ruby_exceptions.html
What is meant by raising an exception of the “RunTimeError”? And, if we
raise it on “ArgumentError”, what is mean by that?
Exceptions are just regular classes in ruby. You can create your own
or use the multitude of built in Exceptions.
Exception are usually very simple classes. The reason why you might
need more than one is differentiation. Sometimes things can go wrong
in more than one way.
Do stuff that raises an exception
rescue MyFirstException => err
puts “MyFirstException occurred”
rescue MySecondException => err
puts “MySecondException occurred”
Usually you can distinguish what an exception is supposed to represent
by its name. RunTimeError is a kind of catch-all error, you can trap
almost every “normal” error using this exception class. An
ArgumentError on the other hand is more specific and is raised when
you try to call methods using the wrong number or type of arguments.
def foo(x, y)
puts x, y
foo(3) => raises ArgumentError