Archived

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

Snakebite

Exception destructors

Recommended Posts

Snakebite    122
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
SteveC    122
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