views:

43

answers:

2

Hi,

I have an application that sometimes causes an access violation on exit. This is quite unpredictable and all attempts to locate the bug have been unsuccesful so far. The bug is harmless, as no data is lost, so I was thinking if it might be possible to just hide it.

Is it possible to have another app launch the buggy one and catch the Access Violation exception if it occurs? If yes, how?

Thanks in advance!

+2  A: 

Yes, if the other application is a debugger. This is a non-trivial amount of work, To become a debugger, you create the process with DEBUG_PROCESS | DEBUG_ONLY_THIS_PROCESS flag, see CreateProcess flags for more information.

Once you are the debugger of the process, you will get first chance to handle all exceptions.

You could also attach to the process as a debugger just before it shuts down (assuming that you know when this is going to happen) with DebugActiveProcess

John Knoeller
+1  A: 

Call SetErrorMode(SEM_NOGPFAULTERRORBOX) before launching the buggy application as a child process.

The error mode is inherited to child processes and this particular flag will prevent the crash dialog from appearing.

Koro