Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to Handle Exceptions in mfc.
Posted
Comments
Albert Holguin 2-Dec-11 9:15am    
This is a pretty vague question that you could have looked up on google. MFC does have some exception handling, but you can also use standard C++ methods.

 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 2-Dec-11 0:47am    
To the point :-), a 5.
--SA
LaxmikantYadav 2-Dec-11 1:02am    
Thanks :)
Albert Holguin 2-Dec-11 9:16am    
+5, although I wish people would google questions like this... :sigh:
try this example
void DoSomeOperation()
{
// Processing
// If something goes wrong...
AfxMessageBox(_T("The x operation failed"));
AfxThrowUserException();
}

BOOL TrySomething()
{
try
{
// Could throw a CUserException or other exception.
DoSomeOperation();
}
catch(CUserException* pe)
{
pe->Delete();
return FALSE; // User already notified.
}
catch(CException* pe)
{
// For other exception types, notify user here.
pe->ReportError();
return FALSE;
}
return TRUE; // No exception thrown.
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900