+ Reply to Thread
Results 1 to 2 of 2

Thread: What are the options for exception handling in MFC?

  1. #1

    What are the options for exception handling in MFC?

    what are the options for exception handling in MFC?

  2. #2
    MFC has built-in support for exception handling.

    You can use any of the derived class of CException. CException class is base class for any of the exception class MFC.

    Following is one example:

    Code:
    void UsingMFCException()
    {
    	try
    	{
    		CFile objFile ;
    		objFile.Open(_T("C:\\File.h"), CFile::modeRead | CFile::modeWrite) ;
    		unsigned char bytes[100] ;
    		objFile.Read(bytes, 100) ;
    	}
    	catch (CFileException *pFileException)
    	{
    		TCHAR szMessage[256] ;
    		pFileException->GetErrorMessage(szMessage, 256, NULL) ;
    		pFileException->Delete() ;
    	}
    	catch (CException *pException)
    	{
    		TCHAR szMessage[256] ;
    		pException->GetErrorMessage(szMessage, 256, NULL) ;
    		pException->Delete() ;
    	}
    }
    In above code, CFileException catch block will get executed if any exception of type CFileException is thrown.

    For any other exception CException will get executed.

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts