RAD Studio |  |

Unwinding Exceptions (C++)

When an exception is thrown, the runtime library takes the thrown object, gets the type of the object, and looks upward in the call stack for a handler whose type matches the type of the thrown object. Once a handler is found, the RTL unwinds the stack to the point of the handler, and executes the handler.

In the unwind process, the RTL calls destructors for all local objects in the stack frames between where the exception was thrown and where it is caught. If a destructor causes an exception to be raised during stack unwinding and does not handle it, terminate is called. Destructors are called by default, but you can switch off the default by using the -xd compiler option.

Note: During the unwind process, the RTL does not call destructors for objects that are allocated on the heap rather than the stack. This is why, for example, VCL applications use finally
blocks to ensure that VCL objects, which are always allocated on the heap, are properly freed. There is one exception to this rule, which is the use of safe pointers.

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!