异常规范
我知道这个功能在 C++0x 中将被弃用,但对于我作为一个新手来说,拥有它似乎是一个好主意。谁能向我解释为什么这不是一个好主意?
I know that this feature will be deprecated in C++0x, but for me as a total novice it seems like a good idea to have it. Could anyone explain to me why isn't a good idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
请参阅 Herb Sutter 撰写的这篇详细文章。他对他们设计中的问题和缺点有最彻底的解释。
务实地了解异常规范
Please see this detailed article by Herb Sutter. He has the most thorough explanation of the problems and short comings of their design.
A Pragmatic Look at Exception Specificiations
据我了解,异常规范意味着:
我不希望你(编译器)生成额外的代码来确保异常是这些类型之一。如果没有请终止,我们干杯。每次调用时都需要将额外的检查放入(隐式)异常处理程序(实现它所需的)。
As far as I understand it, an exception specification means:
I wan't you (the compiler) to generate extra code that makes sure that the exception is one of these types. If not call terminate please, we're toast. The extra checking would need to be put into the (implicit) exception handler (required to implement it) in every call.
回顾http://www.gotw.ca/publications/mill22.htm
确实是一个小技术点,而且很容易修复。
他的第一点:
如果这是人们的想法,那很好,因为这正是 ES 所保证的,根据定义。 Herb 在同一份文件中表示同意:
他的第二点:
这也是绝对正确的。
他用一个例子解释了为什么第二点是错误的信念:
Herb 后来说“(ES) 在运行时强制执行 函数只会抛出列出的异常(可能没有)。”也反驳了这个“论点”。
赫伯的两个要点显然、绝对、无可争议地都是错误的,在他看来。
我还可以添加什么?
我相信词语都有固定的含义,不能为了“论证”而随意改变。
Review of http://www.gotw.ca/publications/mill22.htm
True, minor technical point, and easy to fix.
His first point:
If this is what people think, it is very fine, because it is exactly what ES guarantee, by definition. Herb agrees in the same document:
His second point:
This is also absolutely correct.
He explains why this second point is an incorrect belief with an example:
Herb latter remark that "(ES) Enforce at runtime that functions will only throw listed exceptions (possibly none)." refute this "argument" too.
Both of Herb's 2 main points are obviously, absolutely, indisputably wrong, according to him.
What else can I add?
I believe that words have fix meaning, that can't be changed at will, for the sake of the "argument".