An intro to throw and catch in Ruby

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 trycatch, and 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 throw and catch… but they don’t seem to be used the way you’re used to in other languages! And there are also these “begin“, “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]

1 comment

Leave a Reply

Your email address will not be published. Required fields are marked *