Exception destructors

Started by
1 comment, last by Snakebite 21 years, 10 months ago
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]
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]
At the end of the catch block, I guess...

Forever trusting who we are
And nothing else matters
- Metallica
Forever trusting who we areAnd nothing else matters - Metallica

This topic is closed to new replies.

Advertisement