In the MFC application, where to put the highest attempt / catch?

In an MFC application, where to put the topmost try / catch?

I have an MFC application and would like to catch all exceptions and show my own message box.

This is my idea for the topmost try / catch block:

try { // What enclose here? Or, where to put this try/catch block? } catch( const std::exception& e ) { ::MessageBox(0,e.what(),"I do not know hot to handle this exception, I will terminate",MB_OK); } catch(...) { ::MessageBox(0,"Unknown Excpetion","I do not know hot to handle this exception, I will terminate",MB_OK); } ::TerminateProcess( ::GetCurrentProcess(), -1 ); 

But where can I put the block? I created an MFC dialog application with Visual Studio 2010 and compiled it in Release x64, I am on Windows 7. I throw std::exception (passing the line to the constructor) in the OnTimer method and without a block I get a message box created by csrss.exe with this general message

"An unknown software exception exception (0x40000015) occurred in the application at location 0x5dff61c9."

"Click OK to complete the program"

"Click" CANCEL "to debug the program"

The message box does not report the line attached to the exception, and therefore it is not so useful. I think I get a message box instead of the fancy TaskDialog because I turned off the Windows Error Reporting Service and renamed WerFault.exe.

Perhaps I need to forget my own message box, and I need to accept the new Windows error reporting?

+4
source share
1 answer

The proper way to handle unhandled exceptions in an MFC application is to override CWinApp::ProcessWndProcException

You can only handle certain types of exceptions. If you want to return to the default behavior in some cases, call the base implementation. If you do not call the database, your application will not be closed.

If you want to display your own error message and then disconnect, avoiding the default message, display a message box and then call DestroyWindow in the main frame / dialog box.

+2
source

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


All Articles