If you are using Linux / Unix: this is what I usually start with:
struct sigaction sa; sa.sa_handler = bt_sighandler; sigemptyset(&sa.sa_mask); sa.sa_flags = SA_RESTART; sigaction(SIGSEGV, &sa, NULL); sigaction(SIGUSR1, &sa, NULL);
If you use Microsoft C ++ for Windows: _try / _except usually does the trick. This is an MSVC extension (you can tell from double underscore) that extends the standard try / catch.
Try / catch catches C ++ exceptions, _try / _except will catch all other unhandled exceptions (COM, Win32, ...). For example, it will catch zero dereferencing, memory access issues that are likely to cause your failure. Read here
Otherwise, in widows, try SetUnhandledExceptionFilter
EDIT: Since the approach using SEH seems to fail, you can go up one level and use Vectored Exception Handling. According to this msdn blog post , VEH is registered for each process and it is checked before SEH.
If all else fails, do not despair :) you can still turn your application into a para debugger / debugee. This will give you complete control over the events, life and death of the opening process. This is usually not worth it, but it is an additional solution that I had to use in the past. It is also not as difficult as it might seem; if something else doesn’t work, let me know and I dig some old code.
source share