Why is throw and catch hardly ever used in Ruby? [closed]

浪子不回头ぞ 提交于 2019-11-29 23:14:20

问题


I have recently gotten into a discussion over raise vs. throw. There is another SO thread discussing this, and the pundits summarized the situation as this:

  • Throw and raise are, to a great degree, interchangeable
  • Advantage of throw is that you can throw easily anything, and that you don't waste time putting together the stack trace

That leaves me with a question, why nobody is actually using throw in Ruby? The thread discussed earlier mentioned use of catch / throw in Sinatra to handle HTTP error codes, but still, I have seen very few catch / throw examples in the wild, and I only used it in my own code once. As current Rails security crisis has shown, Ruby community widely ignores important features ($SAFE level in this particular case). So what is the thing with catch / throw?

来源:https://stackoverflow.com/questions/16972757/why-is-throw-and-catch-hardly-ever-used-in-ruby

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!