set_terminate handler for uncaught exception

S

siddhu

Dear experts,

Is it a standard behavior that set_terminate handler function gets
called if an exception is thrown and not caught anywhere in the
program?
I know its a C++ forum and I'm facing a problem which is related to
MSDEV but I hope I'll get a solution here for my problem.

I installed a handler in set_terminate() to keep track of crashes and
normal termination. If the handler function is the part of exe it gets
called.

If handler function is in some loaded dll then it does not get
called.



e.g. Code given below works ( i.e. set_terminate handler function gets
called when program has an uncuaght exception), But if handlers are
from a loaded dll then atexit() handler gets called.

And I can not make handlers as part of exe. I have to keep them in a
separate dll.



Any suggestion would be of great help.







#include<iostream>



void term_func()

{

std::cout<<"in term_func"<<std::endl;

abort();

}



void exit_func()

{

std::cout<<"in exit_func"<<std::endl;

}

void func()

{

throw 1;

}



int main(int argc, char *argv[])

{

set_terminate(term_func);

atexit(exit_func);

func();

return 0;

}



Thanks

Siddharth
 
E

Erik Wikström

Dear experts,

Is it a standard behavior that set_terminate handler function gets
called if an exception is thrown and not caught anywhere in the
program?
Yes.

I know its a C++ forum and I'm facing a problem which is related to
MSDEV but I hope I'll get a solution here for my problem.

I installed a handler in set_terminate() to keep track of crashes and
normal termination. If the handler function is the part of exe it gets
called.

If handler function is in some loaded dll then it does not get
called.



e.g. Code given below works ( i.e. set_terminate handler function gets
called when program has an uncuaght exception), But if handlers are
from a loaded dll then atexit() handler gets called.

And I can not make handlers as part of exe. I have to keep them in a
separate dll.

You should ask in a MS newsgroup, perhaps microsoft.public.vc.language.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,246
Latest member
softprodigy

Latest Threads

Top