views:

145

answers:

1

Hi,

Is there anyway to catch all uncaught exceptions in a MFC VC++ 2008 application? Is there something like this Java code:

Thread.currentThread().setUncaughtExceptionHandler(
new Thread.UncaughtExceptionHandler() {
   public void uncaughtException(Thread t, Throwable e) {
       System.out.println("Oops! We have a exception in Thread '" + t.getName() + "': " + e.toString());
   }
});

The handler should preferably catch all types of exceptions.

+1  A: 

It depends what you are trying to catch. If you just want C++ exceptions then look at setting your own handlers using set_unexpected or set_terminate. If you want all Windows exceptions then you use SetUnhandledExceptionFilter to specify a top level handler.

Catching all Windows exceptions should in most cases catch all C++ exceptions as well but it is not always the case so you are best to use both approaches to catch as much as possible. There are some oddities with the last CRTs (see this) which might mean not all exceptions get caught.

tyranid