std::terminate handler is not called

Viewed 35

I was trying sample program to understand how std::terminate feature works - but on VC++ 2019 I always get an un-handled exception error:

// 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;
    }

I always get the below error in VC++ -

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

Whereas the expected output is -

terminate handler called
Aborted

What wrong am I doing?

0 Answers
Related