troubleshooting Question

Getting error information from catch(...)

Avatar of TheIronDuke
TheIronDuke asked on
C++System Programming
8 Comments3 Solutions338 ViewsLast Modified:
I am managing exceptions using C++ MFC using the catch(...) option. Is there any way to get more information using this exception handler, more than just "and exception occurred"? Like Windows getLastError() or something?

Any help would be appreciated.
void myProgram
{
	CStdioFile		file;
	CString			szPath = _T("Myfile.txt");
	CString			szData,szError;
	bool			bFound = false;
	int				nErrors = 0;
	TCHAR			szCause[255];

	try
	{
		file.Open(szPath,  CFile::modeNoTruncate | CFile::modeReadWrite);
		file.SeekToEnd();
		while( file.ReadString(szData) && !bFound && !nErrors )
		{
			if( szData.Find(_T("MyName="),0) >= 0 )
			{
				someProcessProgram(szData);
				bFound = true;
			}
		}

		file.Close();

	}
	catch( CException* e )
	{
		e->GetErrorMessage(szCause,255);
		e->Delete();
		szError.Format(_T("An exception occurred while reading data.\nWindows reports: %s"),szCause);
		nErrors++;
		AfxMessageBox(szError);
	}
	catch( std::exception* e )
	{
		szError.Format(_T("An exception occurred while reading data.\nWindows reports: %s"),e->what());
		nErrors++;
		AfxMessageBox(szError);
	}
	catch(...)
	{
		szError = _T("An exception occurred while reading data.");
		nErrors++;
		AfxMessageBox(szError);
	}

}
ASKER CERTIFIED SOLUTION
Zoppo

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 3 Answers and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 3 Answers and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros