I have a command line application written in C++ and compiled with Visual Studio 2015.
I need to make sure this application doesn't get blocked by error dialogs during automatic, unattended functional testing, in particular in the case of failing assertions (standard assert() from <cassert>).
I initially thought that the following call suggested in https://stackoverflow.com/a/6925695/393756 would do the job, but it didn't:
_set_error_mode(_OUT_TO_STDERR);
By experimenting I eventually found out that the following code achieves the intended effect, at least when it comes to failing assertion dialogs:
SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX);
_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
_CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE);
_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
Questions:
Why isn't
_set_error_mode(_OUT_TO_STDERR)sufficient? If I understand the documentation correctly, it should.Why isn't
_CrtSetReportMode(_CRT_ASSERT)(plus the associated_CrtSetReportFile()call) sufficient to disable dialogs for assertions? Apparently I need to also configure_CRT_ERROR.In order to make sure that no dialog is ever opened, should I call
SetErrorMode(), and if so with what arguments?Should I prefer
SetThreadErrorMode()?