如果定义了 throw() 表示函数不抛出异常,这时候如果还是抛出,会导致运行时错误。

#include <iostream> #include <exception> #include <stack> using namespace std; void func() throw() { int x = 5; throw x; } int main() { std::cout << "Hello, World!" << std::endl; try { func(); } catch(int &x) { std::cout << x << endl; } catch (...) {