I really don’t see a sane use for these. There is already rescue and raise, so why the need for throw and catch? It seems they are supposed to be used to jump out of deep nesting, but that just smells like a goto to me. Are there any examples of good, clean use for these?
I really don’t see a sane use for these. There is already rescue and
Share
Note: It looks like a few things have changed with catch/throw in 1.9. This answer applies to Ruby 1.9.
A big difference is that you can
throwanything, not just things that are derived fromStandardError, unlikeraise. Something silly like this is legal, for example:but it’s not terribly meaningful. But you can’t do: