I’ve got a guest post up at the RubyLearning blog today, an introduction Ruby’s throw/catch construct. It’s a bit more novice-oriented than the stuff I typically post here. Here’s an excerpt:
If you’re familiar with Java, C#, PHP, or C++, you are probably used to using
throw for exception handling. You use
try to delineate the block in which you expect an exception may occur. You use
catch to specify what to do when an exception is raised. And you use
throw to raise an exception yourself.
You’ve probably noticed that Ruby has
catch… but they don’t seem to be used the way you’re used to in other languages! And there are also these “
raise” and “
rescue” statements that seem to do the same thing. What’s going on here?
Head on over to RubyLearning to read the rest of the article! [UPDATE: Content moved to this site because the original fell off the web]