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?