Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: C++
Expertise: All
Nov 12, 1999

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
}
Danny Kalev
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap