c++ - 在 C++ 语法中抛出异常

标签 c++ exception

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

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/

相关文章:

python - 避免 Python 中的多个 Try/Except block

c++ - 编译 C++ 代码使其在 Windows 和 Linux 中表现相同

android - 不同图像分辨率之间的SSIM

java - 在 Java 中声明一个大尺寸的 2d Double 数组

c# - catch 子句的顺序

Java:迭代 BiMap - 给我带来了一些问题

Python、IoC、异常和松耦合

c++ - 获取所有边 ID 的 vector

c++ - 添加 additional-include-directory 和 reference => 指向一个设置中的静态库

c++ - R-树 : should I reinvent the wheel?