Re: How to tell if an exception has currently been thrown and is
being processed ?
On Aug 31, 2:34 pm, Timothy Madden <terminato...@gmail.com> wrote:
Hello
What is the function that could tell if there is an exception currently
being thrown, that is causing stack unwinding ? I guess it was a
function returning true during unwinding and false otherwise.
uncaught_exception, perhaps?
Also, is there a way to get the current exception object (other then as
the argument to the catch handler) ?
Well, what's wrong with the catch itself? If you want to inspect
somehow your exception while it unwinds, it's sufficient to catch it,
read it, then re-throw it.
Is there a way to store or keep the exception object (and its type) for
later processing outside of the handler or the try-catch function that
caught it ?
AFAIK, no. I'd try employing "cloneable" interface and clone the
exception from the catch.
class /*interface*/ i_cloneable { virtual base* clone(); }
base* p = NULL;
try
{
}
catch(const exception& e)
{
i_cloneable* original = dynamic_cast<i_cloneable*>(&e);
if (original)
p = original->clone();
else
p = clone_of(e); // Exercise for the reader. ;-)
}
Goran.
P.S. Obviously, your post begs a MASSIVE "why do you think you need
this?" 'Cause you do not seem to use exceptions the way they are meant
to be used (as seen by your need to "see" them outside the catch).
Normally, only place where you do not have an anonymous exception
object is said catch. And that goes for many other languages, C++ is
not special in this respect. Chances are, you are doing something
wrong.