devxlogo

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<<"an exception has occurred";      return;    }//x is destroyed at this point}
See also  Professionalism Starts in Your Inbox: Keys to Presenting Your Best Self in Email
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist