jirentabu / crashrpt

Automatically exported from code.google.com/p/crashrpt
0 stars 0 forks source link

Some MFC exceptions are not handler #197

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
 I found that certain MFC exceptions were not being trapped by crashreport.  Here’s some code to put into CMFCDemotApp::OnAppAbout() that will show the issue:

// App command to run the dialog
void CMFCDemoApp::OnAppAbout()
{
// Create an mfc array with 10 doubles, for example.
typedef CArray<double,double> CDoubleArray;
CDoubleArray dArray;
dArray.SetSize(10);
for(int i=0; i<10; i++)
  dArray.SetAt(i, i*3.14);

// Read off the end of the array
// This with throw an mfc exception when i==10
// The exception will not be trapped by CrashRpt.
double sum=0.0;
for(int i=0; i<100; i++)
  sum += dArray.GetAt(i);

CAboutDlg aboutDlg;
aboutDlg.DoModal();
}

The standard MFCDemo with CrashRpt doesn’t trap this exception.  MFC reports 
"Encountered an Improper Argument".  After researching this a bit, I found an 
approach that makes it work with CrashRpt.  The key is to add an override to 
CWinApp::ProcessWndProcException() in the application class.  This method is 
called by MFC when there’s an unhandled MFC exception.  Here’s my override 
for MFCDemo:

LRESULT CMFCDemoApp::ProcessWndProcException(CException* e, const MSG* pMsg)
{
// This is where we land with some MFC exceptions.
// If we needed to show a message or something, we could do that here.
// However, in most cases, we just want to cause MFC to throw the exception out 
to CrashRpt.

// Make MFC throw (and not catch) this exception so that CrashRpt can catch it.
THROW_LAST();

return 0;
//return CWinApp::ProcessWndProcException(e, pMsg);
}

With this override in place, the MFC exception eventually finds its way into 
the CrashRpt handlers and we proceed with the crash report generation.

Original issue reported on code.google.com by zexspect...@gmail.com on 17 Apr 2013 at 2:13

GoogleCodeExporter commented 9 years ago

Original comment by zexspect...@gmail.com on 17 Apr 2013 at 2:19