Hello everyone,
This question is about when it is allowed to call throw to re-throw exception -- make the exception re-throw.
I can only think of two situations,
1. in catch block of an exception;
2. in unexpected handler.
For (2), in unexpected handler, since the input parameter is null, so in order to get the exception information, we need to re-throw it and catch it to get exception informaiton.
Is my understanding correct? Here is some pseudo code from Bjarne's book.
Code:
// suppose throwY is unexpcted handler
void throwY() throw (Yunexpected)
{
try{
throw; // have to re-throw and catch in order to get exception information since current input parameter is null and has no exception information, my understanding correct?
} catch (Network_exception& p)
{
throw (Yunexpected (&p));
} catch (...)
{
throw (Yunexpected (0));
}
}
thanks in advance,
George