在Ruby中引发异常与引发异常之间有什么区别?
时间:2020-03-05 18:49:45 来源:igfitidea点击:
Ruby有两种不同的异常机制:抛出/捕获和提升/救援。
为什么我们有两个?
什么时候应该使用一个而不是另一个?
解决方案
回答
我认为http://hasno.info/ruby-gotchas-and-caveats对区别有一个不错的解释:
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.