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

例如

void foo(void) throw(const char *) {};

什么时候才是合适的时间。如果我们要以这种方式声明/定义它,我们是否要同时使用原型(prototype)和定义,也可以只使用定义。如果我们还包括其他内容,那么使用构造函数执行此操作的语法是什么。

例如
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

关于c++ - 用C++语法抛出异常,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7459655/

10-11 22:06