The Memory of an Exception Object

The Memory of an Exception Object

The memory for the temporary copy of an exception that is being thrown is allocated in a platform-defined way. Note, however, that it may not be allocated on the free store, and in general, such objects are allocated on a special exception stack. The temporary persists as long as a handler for that exception is executing. If a handler exits by executing a throw statement (i.e., the handler re-throws the exception), control passes to another handler for the same exception, so the temporary remains. Only when the last handler for that exception has terminated is the temporary object destroyed, and the implementation may deallocate its memory. For example:

           class X();  int main()  {    try    {      throw X();    }    catch (X x) //catch by value    {      cout


Share the Post: