Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I disable "Microsoft Visual C++ Debug Library" exception dialogues?

If I run an executable that throws an exception ( built in debug ), I will receive an error dialog, saying something like "Debug assertion failed" and then some information about the exception. While this happens, the program's execution is suspended, until I choose one of "Abort", "Retry" or "Ignore" options.

The thing is, I run a lot of applications from a script, and if one of them throws an exception, it pauses my script until it's handled.

Is there someway to disable this exception handling mechanism?

EDIT: I remember reading about a registry key, a while ago, which would disable the error messages from appearing. Does anyone know about it?

like image 993
Geo Avatar asked Aug 05 '10 07:08

Geo


3 Answers

If you can modify the source, the abort behavior (called by assert) needs to be modified to suppress the abort/retry/ignore dialog.

On abort, a crashdump will still be produced (by default) so you won't lose what is important.

Additionally, you can adjust the assert behavior to write to stderr only. This is NOT required if the abort behavior is adequate for what you want. Note: the _Crtxxx calls are only active in debug builds (/Zi).

A minimal change to disable the abort/retry/ignore. Uncomment the _Crt calls and include crtdbg.h to also modify the assert behavior in debug mode builds.

#include <stdlib.h>
//#include <crtdbg.h>
int main(int argc,char **argv);
int main(int argc,char **argv)
{
    // ON assert, write to stderr.
    //_CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_FILE );
    //_CrtSetReportFile( _CRT_ASSERT, _CRTDBG_FILE_STDERR );

    // Suppress the abort message
    _set_abort_behavior( 0, _WRITE_ABORT_MSG);

    abort();
    return 0;
}

msdn assert mode

like image 20
rickfoosusa Avatar answered Oct 14 '22 11:10

rickfoosusa


If you can modify the source of the application(s), have a look at the _CrtSetReportMode function, eg:

_CrtSetReportMode(_CRT_ASSERT, 0);

See msdn for more.

like image 172
ngoozeff Avatar answered Oct 14 '22 12:10

ngoozeff


Can you build your executables as release? If I recall, that should stop the assertion errors from appearing.

like image 24
Lizzan Avatar answered Oct 14 '22 12:10

Lizzan