Exception Processing
When a program executes, a number of abnormal conditions and errors called "exceptions" can occur. These may include running out of memory, resource allocation errors, and failure to find files.
The Microsoft Foundation Class Library uses an exception-handling scheme that is modeled closely after the one proposed by the ANSI standards committee for C++. An exception handler must be set up before calling a function that may encounter an abnormal situation. If the function encounters an abnormal condition, it throws an exception and control is passed to the exception handler.
Several macros included with the Microsoft Foundation Class Library will set up exception handlers. A number of other global functions help to throw specialized exceptions and terminate programs, if necessary. These macros and global functions fall into the following categories:
Exception macros, which structure your exception handler.
Exception-throwing functions, which generate exceptions of specific types.
Termination functions, which cause program termination.
For examples and more details, see the article Exceptions.
Exception Macros
Designates a block of code for exception processing. |
|
Designates a block of code for catching an exception from the preceding TRY block. |
|
Designates a block of code for catching all exceptions from the preceding TRY block. |
|
Designates a block of code for catching additional exception types from the preceding TRY block. |
|
Designates a block of code for catching all other additional exception types thrown in a preceding TRY block. |
|
Ends the last CATCH or AND_CATCH code block. |
|
Ends the last CATCH_ALL code block. |
|
Throws a specified exception. |
|
Throws the currently handled exception to the next outer handler. |
Exception-Throwing Functions
Throws an archive exception. |
|
Throws a file exception. |
|
Throws a memory exception. |
|
Throws a not-supported exception. |
|
Throws a Windows resource-not-found exception. |
|
Throws an exception in a user-initiated program action. |
MFC provides two exception-throwing functions specifically for OLE exceptions:
OLE Exception Functions
Throws an exception within an OLE automation function. |
|
Throws an OLE exception. |
To support database exceptions, the database classes provide two exception classes, CDBException and CDaoException, and global functions to support the exception types:
DAO Exception Functions
Throws a CDaoException from your own code. |
|
Throws a CDBException from your own code. |
MFC provides the following termination function:
Termination Functions
Called to terminate an application when a fatal error occurs. |