Exceptions
There are many ways code can fail. Some failures are detected at analysis time, such as a method not being implemented or a nil
value in a variable that shouldn't contain nil
. Some other failures happen during the program's execution and are described by special objects: exceptions. An exception represents a failure on the happy path, and it holds the exact location where the error was detected, along with details to understand it.
An exception can be raised at any point using the raise
top-level method. This method won't return anything; instead, it will begin walking back on all the method calls as if they all had an implicit return
. If nothing captures the exception higher in the method chain, then the program will abort, and the exception's details will be presented to the user. The nice aspect of raising an exception is that it doesn't have to stop the program's execution; instead, it can be captured and handled, resuming normal execution...