Exceptional Exception Handlers
As a budding developer, I quickly discovered that there's nothing quite as satisfying as debugging a frustrating error after hacking away at it for what seems to be an eternity. But sometimes error messages aren't very clear and it can make the debugging process especially difficult. Enter exception handlers ! Before we dive into just what an exception handler is and does, we need to take a look at a key question - what is an error and how are errors raised? In Ruby, an error is an instance of the predefined class Exception that is raised (or thrown) when something has gone wrong. By default, Ruby programs terminate when an exception occurs, unless you have an exception handler - a block of code that is executed when an exception occurs. To handle exceptions, we can enclose the code that could throw an exception in a begin-end block and use one or more rescue clauses to tell Ruby the types of exceptions to handle. Note that the body of a me...