首页 > 解决方案 > 未调用 std::terminate 处理程序

问题描述

我正在尝试示例程序以了解 std::terminate 功能的工作原理 - 但在 VC++ 2019 上,我总是收到未处理的异常错误:

// set_terminate example

#include <iostream>       // std::cerr
#include <exception>      // std::set_terminate
#include <cstdlib>        // std::abort

    void myterminate () {
      std::cerr << "terminate handler called\n";
      abort();  // forces abnormal termination
    }
    
    int main (void) {
      std::set_terminate (myterminate);
      throw 0;  // unhandled exception: calls terminate handler
      return 0;
    }

我总是在 VC++ 中得到以下错误 -

Unhandled exception at 0x761340B2 in Abandon.exe: Microsoft C++ exception: int at memory location 0x0097FAE8

而预期的输出是 -

terminate handler called
Aborted

我在做什么错?

标签: c++visual-c++c++14

解决方案


推荐阅读