We help IT Professionals succeed at work.

Hook Abnormal Termination Popup Window

eric3333
eric3333 asked
on
Hi
I want to change the default behavior when a not catched excection occurs in my program.
Today an abnormal termination program window popups.
My applicaiton is a MFC C++ application.

I try with SetUnhandledExceptionFilter and it works but not for all type of exception.
For example a throw not catched is not handle by this hook.

I try with _set_se_translator, set_terminate and set_unexpected but the same.

What i need is to change default behaviour of ANY uncatched exceptoin of ANY thread of my application.

Is this possible ?

Thanks

Comment
Watch Question

Commented:
In your InitInstance do this call:

SetErrorMode( SEM_NOGPFAULTERRORBOX );

Application will be terminated without popup.

Author

Commented:
Does not work.
Uncatched exception still show abnormal termination window.

For example if i do :
throw new CException();
without handler the abnormal dialog box is displayed :(
Commented:
Try this solution:

Define a function like the following:

LONG WINAPI MyUnhandledExceptionFilter(struct _EXCEPTION_POINTERS *ExceptionInfo)
{
      AfxMessageBox( "Handled" );

      exit( 0 ); // or do something else (see SetUnhandledExceptionFilter() documentation for more informations)
}

At the begin of your InitInstance ( before to throw your exception) add the following line:

      SetUnhandledExceptionFilter( MyUnhandledExceptionFilter );


!!!!!! MyUnhandledExceptionFilter  will catch the exception only if the debuf is not active!!!!!!!!!!!!

Author

Commented:
Arf. Good , near perfect but .....

I need to implement one handler for each thread.
This is ok but the problem is my program have a lot of threads and some are launched and managed by an api i cannot enter (i just have binary code).

Not perhaps now i just have to find a way to force the handler of all thread s....

Forced accept.

Computer101
EE Admin

Explore More ContentExplore courses, solutions, and other research materials related to this topic.