nobalG
nobalG

Reputation: 4620

about setting up the set_terminate function

i am using a visual studio c++ compiler,& during my study on exception handling,i came across a number of features that can't be supported by visual c++ compiler, like controlling the exceptions that can be thrown out of a function. also i was unable to modify the functioning of terminate() using set_terminate() . is it a specification too for visual c++ to modify terminate()?...& if so,then can anyone explain that why microsoft is creating these specifications in its compilers?...:-x

Upvotes: 3

Views: 1988

Answers (1)

cprogrammer
cprogrammer

Reputation: 5665

what do you mean you were unable to modify terminate

have you tried something like this ?

// set_terminate example
#include <iostream>
#include <exception>
#include <cstdlib>
using namespace std;

void myterminate () {
  cerr << "terminate handler called\n";
  abort();  // forces abnormal termination
}

int main (void) {
  set_terminate (myterminate);
  throw 0;  // unhandled exception: calls terminate handler
  return 0;
}

Don't try to run from VS. Compile and exec from command line.

Upvotes: 1

Related Questions