Each of these lines will raise a RuntimeError 👇🏽
raise
raise "hello"
raise RuntimeError, "hello"
raise RuntimeError.new("hello")How does the raise method work?
- If the first argument is a string, it raises the
RuntimeErrorwith the string as an argument - If the first argument is the name of an Exception class, it raises the exception
- Else, the first argument should be an object returns an Exception object when the
exceptionmethod is called on the object. The object should look like this 👇
def exception
Exception.new("hello")
end- All exception objects have a method
exceptionwhich returnsself