抛出c++语法中的异常

Throwing exceptions in c++ syntax

本文关键字:异常 语法 c++ 抛出      更新时间:2023-10-16

对于抛出异常,我知道您可以声明/定义函数并暗示它抛出异常

void foo(void) throw(const char *) {};
什么时候做这件事比较合适?如果我们要用这种方式声明/定义它,我们是同时使用原型和定义还是只使用定义?还有一件事,如果我们包含了其他东西,构造函数的语法是什么?

class bar
{
 bar() , a(a) would the throw go here, and would it also in the definition if written elsewhere ?
}

谢谢:-)

不要这样做,它在c++ 11中被弃用有一个很好的理由:它不做人们认为它做的事情。

更新:更多关于这个主题的信息在这里http://www.boost.org/development/requirements.html#Exception-specification

另一个更新:正如@Steve Fallows指出的,这里是关于这个主题的另一个很好的参考:http://www.gotw.ca/publications/mill22.htm