对于抛出异常,我知道您可以声明/定义函数,暗示它会抛出异常
EX。
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/