提升异常与Ruby中的抛出异常有什么区别? [英] What is the difference between Raising Exceptions vs Throwing Exceptions in Ruby?
本文介绍了提升异常与Ruby中的抛出异常有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么我们有两个?
$ b $你应该什么时候使用而不是其他的?
解决方案
我认为 http://hasno.info/ruby-gotchas-and-caveats 有一个不同的解释:
抓取/抛出与加注/抢救不一样。捕获/抛出允许您快速退出块返回到为特定符号定义捕获点的位置,提升拯救是涉及异常对象的真正异常处理。
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?
解决方案
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.
这篇关于提升异常与Ruby中的抛出异常有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文