G
Grahamo
My question pertains to exceptions and their destruction
Say I do this in my (pseudo) code;
class an_exception
{
// details/methods for exception etc.
~an_exception() { .... }; };
try
{
foo();
}
catch (const an_exception& ex)
{
// handle the exception
}
void foo() throw (an_exception)
{
if (something)
an_exception ex;
throw (ex);
}
At what point is the destructor for the an_exception object called? Is
a copy taken at the point of "throw" and the "ex" instance destroyed
before the throw statement executes?
the reason I ask is to clarify another piece of code I saw whereby the
exception is newed and then thrown. The caller catches a pointer to the
exception. something like;
throw (new an_exception());
and the calling code obviously changes to handle the throw.
Anyhows I'm more interested in the pseudo code for the moment just to
get a handle on what happens when the exception is thrown by value.
Say I do this in my (pseudo) code;
class an_exception
{
// details/methods for exception etc.
~an_exception() { .... }; };
try
{
foo();
}
catch (const an_exception& ex)
{
// handle the exception
}
void foo() throw (an_exception)
{
if (something)
an_exception ex;
throw (ex);
}
At what point is the destructor for the an_exception object called? Is
a copy taken at the point of "throw" and the "ex" instance destroyed
before the throw statement executes?
the reason I ask is to clarify another piece of code I saw whereby the
exception is newed and then thrown. The caller catches a pointer to the
exception. something like;
throw (new an_exception());
and the calling code obviously changes to handle the throw.
Anyhows I'm more interested in the pseudo code for the moment just to
get a handle on what happens when the exception is thrown by value.