There are bad design decisions, and there are horrible design decisions. The exception class Timeout::Error in Ruby's stdlib is one of those horrible things.
Ok, let me start from the beginning. In Ruby, the standard way to catch any recoverable error in your program is to catch StandardError. Anything that doesn't inherit from StandardError is generally the type of thing that you want to have crash your program. Now, Ruby has a library for having an exception thrown after a timeout. (We'll ignore for a second that this library is implemented in a
provably unsafe manner as far as threads are concerned.) You just call the timeout method, and pass a number of seconds and a block. If the block doesn't terminate after the number to seconds, it is forcibly terminated, and the Timeout::Error exception is called. This would be all hunky dory except that Timeout::Error
isn't a subclass of StandardError, it's a subclass of Interrupt. "So," one may say, "why even use this thing at all?" Well, because you kinda have to. Want to do something with HTTP? Well, the standard HTTP library happily uses the timeout library to do it's timeouts. And as a result, so does pretty much every other library that has to do something with HTTP. So you're going along in your nice, happy application, when you suddenly find out that even though you're rescuing StandardError so that a network failure doesn't bring down your application, well, that isn't quite true: the minute a network timeout happens, your entire application comes crashing down. The only answer I can find on the internet is that one should always just rescue Timeout::Error when doing anything that might call the timeout library. (
rant from a developer that found this way before I did)
What I don't get is how this is still in the standard library. Why not do the obvious thing and just make Timeout::Error a subclass of StandardError? (Of course, the aforementioned problems with the timeout library should be fixed, but I can see that taking a long time) While I forsook Perl in favor of Ruby because of Perl's many gotchas, at least Perl's evil tends to be in my code, not hidden deep in a library that I'm using. And I still miss Perl's copious, usually well written documentation. (Even CPAN modules tend to be rather well documented)
Sometimes, the land of Python seems like it might be nice... (The grass is always greener on the other side, and there is always something hidden in the grass waiting to bite you.)
(I also have a whole rant about the stupidity of Java's properties object inheriting from Hashtable, but that's
a lot less insidious.)
(Yet Another Parenthesized note: maybe I just need to go back to my warm, fuzzy, Perl security blanket.)