• Advertisement

Archived

This topic is now archived and is closed to further replies.

Exception destructors

This topic is 5733 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I can throw a local object out of the current scope and I can catch objects by reference, so when is their destructor called? Example:
class E
{
};

void f1()
{
   try
   {
      f2();
   }
   catch (const E& e)
   {
      // do something with e
   }
}

void f2()
{
   E  e;

   throw e;
}
 
[edited by - snakebite on June 10, 2002 11:19:45 AM]

Share this post


Link to post
Share on other sites
Advertisement
It should happen after the current exception chain finishes - either by a catch with a specific type or a generic catch

It should happen right at the first try/catch block to intercept the exception, unless you have rethrown the exception via throw ( with no arguments )

Note that throwing an exception ALWAYS makes a COPY of the object to be thrown

you could make a class and put something in its destructor to see what happens when you throw it as an exception.

[edited by - SteveC on June 10, 2002 10:44:43 AM]

Share this post


Link to post
Share on other sites

  • Advertisement