我有以下代码取自cplusplus.com:
// set_terminate example
#include <iostream>
#include <exception>
#include <cstdlib>
using namespace std;
void myterminate () {
cout << "terminate handler called\n";
abort(); // forces abnormal termination
}
int main (void) {
set_terminate (myterminate);
throw 0; // unhandled exception: calls terminate handler
return 0;
}
由于代码中存在未处理的异常,因此需要调用 myterminate() 函数,该函数被设置为终止处理程序,并应该覆盖默认的终止处理程序。
程序崩溃但未调用 myterminate()。我使用的是 Visual C++ 2008 Express 版。
代码有什么问题吗?
一种可能性 - 如果您在 VC++ 调试器中运行程序,调试器会捕获未处理的异常,并且它可能不会将控制权返回给正在运行的程序来运行 myterminate。尝试在 Visual C++ 之外运行您的程序。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)