Where are catch and throw useful in Ruby?

前端 未结 4 584
囚心锁ツ
囚心锁ツ 2021-01-17 19:20

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 seem

4条回答
  •  北恋
    北恋 (楼主)
    2021-01-17 20:01

    The difference between the two is that you can only 'raise' exceptions but can 'throw' anything (1.9). Other than that, they should be interchangeable, that is, it should be possible to rewrite one with another, just like the example given by @john-feminella.

提交回复
热议问题