Skip to content

Latest commit

 

History

History
22 lines (15 loc) · 1.81 KB

exceptions-examining-exception-contents.md

File metadata and controls

22 lines (15 loc) · 1.81 KB
description title ms.date helpviewer_keywords ms.assetid
Learn more about: Exceptions: Examining Exception Contents
Exceptions: Examining Exception Contents
11/04/2016
exception handling [MFC], MFC
try-catch exception handling [MFC], MFC function exceptions
catch blocks, MFC function exceptions
CException class [MFC], class exceptions
try-catch exception handling [MFC], exception contents
throwing exceptions [MFC], exception contents
dfda4782-b969-4f60-b867-cc204ea7f33a

Exceptions: Examining Exception Contents

Although a catch block's argument can be of almost any data type, the MFC functions throw exceptions of types derived from the class CException. To catch an exception thrown by an MFC function, then, you write a catch block whose argument is 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, which 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.

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

[!code-cppNVC_MFCExceptions#13]

For more information, see Exceptions: Freeing Objects in Exceptions and Exceptions: Catching and Deleting Exceptions.

See also

Exception Handling