sharkin
sharkin

Reputation: 12498

How to swallow crash report when using Win32::CreateProcess

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?

Upvotes: 1

Views: 354

Answers (2)

Hans Passant
Hans Passant

Reputation: 942010

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.

Upvotes: 3

Kate Gregory
Kate Gregory

Reputation: 18964

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.

Upvotes: 0

Related Questions