Implementations may vary, but there are some basic ideas that arise from the requirements.
The exception object itself is an object created in one function, destroyed in its caller. Therefore, it is usually not possible to create an object on the stack. On the other hand, many exception objects are not very large. Ergo, you can create, for example, a 32-byte buffer and an overflow to heap if you really need a larger exception object.
Regarding the actual transfer of control, there are two strategies. One of them is to write enough information onto the stack to expand the stack. This is basically a list of destructors to run and exception handlers that can catch the exception. When an exception occurs, run the stack executing these destructors until you find the appropriate catch.
The second strategy moves this information to tables outside the stack. Now that an exception is raised, the call stack is used to determine which input areas are entered but not displayed. They are then scanned in static tables to determine where the thrown exception will be handled and which destructors are executed between them. This means that the stack has less exception costs; return addresses are needed anyway. Tables are additional data, but the compiler can put them in a program segment loaded on demand.
MSalters Jan 29 '09 at 10:19 2009-01-29 10:19
source share