What is the difference between Raising Exceptions vs Throwing Exceptions in Ruby?

Viewed 55773

Ruby has two different exceptions mechanisms: Throw/Catch and Raise/Rescue.

Why do we have two?

When should you use one and not the other?

3 Answers

I think http://hasno.info/ruby-gotchas-and-caveats has a decent explanation of the difference:

catch/throw are not the same as raise/rescue. catch/throw allows you to quickly exit blocks back to a point where a catch is defined for a specific symbol, raise rescue is the real exception handling stuff involving the Exception object.

Related