如果定义了 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 (...) {
        cout << "here catch" << endl;
    }

    return 0;
}
View Code

相关文章:

  • 2021-05-01
  • 2021-06-05
  • 2022-12-23
  • 2021-12-12
  • 2021-07-23
  • 2022-12-23
  • 2021-06-04
  • 2021-11-11
猜你喜欢
  • 2022-01-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-12
  • 2021-04-23
  • 2022-12-23
相关资源
相似解决方案