I’m feeling kinda tired, so the chapter on exceptions is gonna be a short one.
Turns out I was getting sick. Bleh. Yay for day-quil! Anyway, the chapter in the book on Exceptions is kinda small. Exceptions work just about exactly the same as they do in Java. Throw and catch aren’t quite the same, however. In ruby you “fail” or “raise” an exception. “throw” and “catch” work for bailing out of loops.
In ruby, exceptions are caught by using “rescue” and behave just like catch in Java. There is also a “finally” type clause, called “ensure”; behaves the exact same way it does in Java. Ruby has the concept of a “retry” which is kinda neat. There is great potential for infinite loops, however, so take care. “raise” in ruby behaves the same way as “throw” in java.
“catch” and “throw” are different. You use it to bail from a loop. Ruby will crawl up the stack when you throw something, looking for the location to catch it. Then it’ll jump outside that loop and finish. I personally think that’s pretty spagetti code inducing, but I can see where it might have its usefulness.
And that’s it. This blag post is really almost as long as the actual chapter. Next up is I/O.

