Libraries, exceptions, and debugging

In some work I was doing with a ruby extension, state_machine. I ended up running into a very frustrating but simple problem with an exception I was receiving. I think this is a good opportunity to talk about exceptions especially with regard to libraries. If you just want the answer, you may want to look toward the end for the solution or how to debug these type of problem.

Exceptions

Exceptions are a very common way in most programming languages to establish that something went wrong. They are unique in that they terminate the current context and move up a level. Depending on language, these may need to be dealt with at the level that receives the exception or it may simply raise the exception to the next higher level automatically.

Exceptions are a bad thing to occur. I bring this up since most languages makes them extremely easy to handle in most cases. This can lead to bad practices of using exceptions to convey different statuses or otherwise something other than an error that is unrecoverable at the level at which it will be raised.

In my experience, exceptions come up most (though not exclusively) in environments where there is an element of classes. This allows for the use of typed exceptions. One of the main advantages to this is the ability to handle different types of exceptions differently. This will become extremely important later.