12.3 Examining Exception Contents

The CATCH macro includes an argument that is used to hold a pointer to a CException object (or an object derived from CException, such as CMemoryException). Depending on the exact type of the exception, you can examine the data members of the exception object to gather information about the specific cause of the exception.

For example, the CFileException type has the m_cause data member that contains an enumerated type that specifies the cause of the file exception. Some examples of the possible return values are CFileException::fileNotFound and CFileException::readOnly.

·To examine exception contents:

The following example shows how to examine the contents of a CFileException. Other exception types can be examined in a similar way.

TRY

{

// do something to throw a file exception

}

CATCH( CFileException, theException )

{

if( theException->m_cause == CFileException::fileNotFound )

TRACE( "File not found\n" );

}

END_CATCH