Exceptions: Catching and Deleting Exceptions

HomeOverviewHow Do IFAQ

The following instructions and examples show you how to catch and delete exceptions. For more information on the try, catch, and throw keywords, see Exception Handling Topics (C++).

Your exception handlers must delete exception objects they handle, because failure to delete the exception causes a memory leak whenever that code catches an exception.

Your catch block must delete an exception when:

Note   When deleting a CException, use the Delete member function to delete the exception. Do not use the delete keyword, because it can fail if the exception is not on the heap.

To catch and delete exceptions

For related information, see Exceptions: Converting from MFC Exception Macros.