How to avoid error dialog box when MSVS C ++ application crashes

When my Visual Studio 2008 C ++ application runs, it sometimes invokes this dialog box.

CommandProcessor.exe has encountered a problem and needs to close.

We regret the inconvenience. If you were in the middle of something, the information you were working on might be lost. For more information about this error, click here.

I tried this in Release and in Debug mode.

(By the way, the debugger shows that this is a division by zero error.)

If this happens, I do not want this dialog, which blocks the application. How to compile my application so that crashes do not display a dialog box?

+3
source share
2 answers

With the / EHa switch, you can use catch (...) to catch all exceptions, including structured exceptions, and write a console message. You can also use VC ++ - specific __try to handle structured exceptions, but it's a bit more complicated for the code.

However, this does not protect you from situations where terminate () is called by the C ++ runtime — for example, when an exception escapes the destructor while unwinding the stack — you will also have to change the terminate () handler by calling set_terminate ().

+6
source

Read the series Exception Handling and Emergency Reporting . You can catch the exception and handle it as you wish (for example, you can save a crash dump).

+4

Source: https://habr.com/ru/post/1724490/


All Articles