views:

84

answers:

2

When my Visual Studio 2008 C++ command-line application crashes, it sometimes produces this dialog.

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

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

I tried this in Release and in Debug mode.

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

If it is going to crash, I don't want this dialog, which blocks the application. How do I compile my application so that crashes do not produce the dialog?

+6  A: 

With /EHa option you can use catch(...) to catch all exceptions included structured exceptions and write a console message. You can also use VC++ - specific __try for structured exception handling instead, but that's a bit harder to code.

However this will not protect you against situations when terminate() is called by the C++ runtime - like when an exception escapes a destructor during stack unwinding - you will also have to change the terminate() handler by calling set_terminate().

sharptooth
/EHa is best set through Project -> Properties -> Configuration properties -> C/C++ -> Code Generation -> Enable c++ exceptions. See http://stackoverflow.com/questions/623373/catching-exception-in-code
Joshua Fox
+4  A: 

Read series of articles Exception Handling and Crash Reporting. It is possible to catch exception and process it as you wish (you can save crash dump for instance).

Kirill V. Lyadvinsky