I’m creating child processes with CreateProcess function in MSVC++ 2010, and before that setting error level with SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
The task is to run console programs and hide any annoying messages like famous “Don’t send” dialog preventing program from being normally finished after critical error.
So, if i create child process containing some error(for example division by 0) it works fine, but when i create subprocess with vector index overflow it causes nonavoidable assert error message(in Debug mode of course). Here is the code of this program:
#include <stdlib.h>
#include <vector>
int main(int argc, char *argv[])
{
int index = atoi(argv[1]);
switch(index)
{
case 0:
{
int k = 3, j = 3;
j -= k;
k = k/j;//division by zero
}
case 1:
{
std::vector<int> k(2);
int i = k.at(2);//index is out of bounds and it causes assert failure
}
}
}
In Release configuration it works fine, but in Debug – it causes an assert error dialog. Of course I can just add _set_abort_behavior to child program code, but it is not an option for me.
Is there any way to surpass this assert error dialog for programs compiled in Debug configuration?
A general way would be to launch the process as a debugee, or create a simple debugger that always ignores unhandled exceptions. There may even be an existing debugger that does this already, I just don’t know of one.
Couple nice things about this approach:
It would get more tricky when you need to do this for the entire sub process tree though, or if you want to make any app “silent” with no message boxes or user input.
Note that these debug assertion dialog windows are typically only enabled on debug builds. For production they should not show up at all.