什么是“特殊”? [英] What is 'exceptional'?

查看:166
本文介绍了什么是“特殊”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找单位测试或OOP原则方面的特殊定义。在谈论异常投掷时,SO几次,我已经看到了这样的评论:嗯,我不会考虑让Foo从酒吧得到例外。 (有没有trollface表情?)



我做了一些谷歌搜索,答案不是即时即将到来。有没有比意见或偏好更好的定义,经验法则或准则?如果一个人说这是例外,另一个人说不,不是,怎么解决这个争议?





$ b $哇,所以有一些答案已经有了,有评论不同意,他们似乎都是答复者的意见:P没人参考了维基百科页面或文章一个来自灰熊的片段。我从这里得到的元回答是没有一致的经验法则,用于何时使用异常。在选择抛出异常时,我觉得自己更有信心采用我自己的个人特质规则。

解决方案

我不同意其他答案需要特殊的东西需要异常。我说特殊是任何时候你想以一种向上传播的对象的方式打破正常的控制流程。



异常是一种语言功能。他们是一个手段结束。他们不是神奇的像任何其他功能一样,当您使用它们时,应该在您需要可以提供的内容的指导下进行指导,而不是按照所谓的方式。


I'm looking for a definition of 'exceptional' in terms of unit testing or OOP principles. Several times on SO when talking about exception throwing, I've seen comments like, "Well, I wouldn't consider getting Foo from Bar to be exceptional." (Is there a trollface emoticon?)

I did some googling and an answer wasn't immediately forthcoming. Are there any good definitions, rules of thumb, or guidelines that are more objective than opinion or preference? If one person says "this is exceptional" and another says "no, it isn't", how does one resolve this dispute?


Edit: Wow, so there are a number of answers already, with comments that disagree, and they all seem to be the opinion of the answerers :P Nobody's referenced a wikipedia page or an article a snippet from a greybeard. The 'meta-answer' I'm taking from this is there is no agreed-upon rule of thumb for when to use exceptions. I feel more confident employing my own, personal, idiosyncratic rules when choosing to throw exceptions.

解决方案

I disagree with the other answers about something needing to be "exceptional" to warrant an "exception". I say "exceptional" is any time you want to break the normal flow of control in the way you can by throwing an upward-propagating object.

Exceptions are a language feature. They're a means to an end. They aren't magical. Like any other feature, when you use them should be guided by when you need what they can provide, not by what they are called.

这篇关于什么是“特殊”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆