2

In unit tests, which may run on unattended build machines, it's not great to have "unittest.exe has stopped working" and other dialogues pop up on debug breaks. I've used the below functions to suppress most of these, and SetUnhandledExceptionFilter, signal and so on to install handlers which print the test that failed, and a stack trace.

_set_abort_behavior(0, _WRITE_ABORT_MSG); // Disable abort message.
_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE); // CRT asserts go to stderr.
_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); // CRT asserts go to stderr.

Unfortunately though, I'm finding that whilst printing messages or the stack trace after an error, sometimes heap corruption is detected which brings up the "unittest.exe has stopped working" dialogue. This is already inside my unhandled exception filter so understandably it can't call that again!

Is there a way to suppress this behaviour, and instead just exit straight away with a custom error code? Or perhaps a smarter way to handle this kind of case?

4

0 回答 0