CException
CException is the base class for all exceptions in the Microsoft Foundation Class Library. The derived classes and their descriptions are listed below:
CMemoryException | Out-of-memory exception |
CNotSupportedException | Request for an unsupported operation |
CArchiveException | Archive-specific exception |
CFileException | File-specific exception |
CResourceException | Windows resource not found or not createable |
COleException | OLE exception |
CDBException | Database exception (that is, exception conditions arising for MFC database classes based on Open Database Connectivity) |
COleDispatchException | OLE dispatch (automation) exception |
CUserException | Exception that indicates that a resource could not be found |
CDaoException | Data access object exception (that is, exception conditions arising for DAO classes) |
CInternetException | Internet exception (that is, exception conditions arising for Internet classes). |
These exceptions are intended to be used with the THROW, THROW_LAST, TRY, CATCH, AND_CATCH, and END_CATCH macros. For more information on exceptions, see Exception Processing, or see the article in Visual C++ Programmer's Guide.
To catch a specific exception, use the appropriate derived class. To catch all types of exceptions, use CException, and then use CObject::IsKindOf to differentiate among CException-derived classes. Note that CObject::IsKindOf works only for classes declared with the IMPLEMENT_DYNAMIC macro, in order to take advantage of dynamic type checking. Any CException-derived class that you create should use the IMPLEMENT_DYNAMIC macro, too.
You can report details about exceptions to the user by calling GetErrorMessage or ReportError, two member functions that work with any of CException’s derived classes.
If an exception is caught by one of the macros, the CException object is deleted automatically; do not delete it yourself. If an exception is caught by using a catch keyword, it is not automatically deleted. See the article in Visual C++ Programmer's Guide for more information about when to delete an exeption object.
CException is an abstract base class. You cannot create CException objects; you must create objects of derived classes. If you need to create your own CException type, use one of the derived classes listed above as a model. Make sure that your derived class also uses IMPLEMENT_DYNAMIC.
#include <afx.h>
Class Members | Base Class | Hierarchy Chart
See Also Exception Processing