views:

39

answers:

2

In a unittest sequence I'm testing if a data corruption error is caught or not (deliberately feeding corrupt data).

In order to treat a program crash (e.g. corrupt data + poor buffer management) as a regular fail-condition I run the program in a child process with CreateProcess. My problem is that if it crashes I get a crash report dialog from Windows and I have to close it for the test-sequence to carry on.

Is there any way of using CreateProcess so that I can swallow the crash report from Windows?

A: 

Probably the best plan is to turn off Windows Error Reporting (Microsoft Error Reporting on XP and earlier) on your test machine, at least for the duration of the test. The exact steps depend on your Windows version, but it's under Control Panel.

Kate Gregory
Thanks for the tip. However, as I failed to specify in the question, the solution must be suitable for environments whith limited or no administration interface. E.g. automated testservers. This is actually why the test sequence needs to proceed unattended.
sharkin
+3  A: 

You cannot do this with CreateProcess(), the child program has to take care of it itself. Two basic ways:

  • use the __try/__except keywords to catch and handle the SEH exception
  • register a callback with SetUnhandledExceptionFilter()

Try to do as little as possible in either case, you have no idea what state the program is in when it suffered the heart attack. Best thing to do is to SetEvent() a named event and have your main process terminate the process.

Hans Passant
SetUnhandledExceptionFilter is the way we do it. That way it won't even get to the "windows error reporting" stage and you can just make it do what you like.
Colen
Thanks Hans. SetUnhandledExceptionFilter() did the trick.
sharkin