【问题标题】:set_terminate function is not working for meset_terminate 函数对我不起作用
【发布时间】:2010-11-07 17:58:28
【问题描述】:

我有以下代码取自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 Edition。

代码有什么问题?

【问题讨论】:

    标签: c++ terminate-handler


    【解决方案1】:

    一种可能性 - 如果您在 VC++ 调试器中运行程序,调试器会捕获未处理的异常,并且它可能不会将控制权返回给正在运行的程序以运行 myterminate。尝试在 Visual C++ 之外运行您的程序。

    【讨论】:

    • 是的。使用 Ctrl+F5 启动程序。
    • @bjskishore123:不,这是一个功能:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-08
    • 2020-11-11
    • 2013-02-13
    相关资源
    最近更新 更多