Re: How to tell if an exception has currently been thrown and is
being processed ?
On Aug 31, 3:25 pm, Timothy Madden <terminato...@gmail.com> wrote:
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.
I use minizip package from zlib-1.2.5 to unpack an archive from my
client's web server given by the URL. zlib uses callbacks for file io
(open, read, write, seek, tell, close, error) functions, that
application will provide and that I will define to eventually
read/write/seek from a CHttpFile.
The problem is CHttpFile and other code in the callbacks have the habit
of throwing exceptions, which I can not let propagate to the
minizip/zlib code invoking them, as that code is written in C and is not
exception-safe. So I have a need to catch the exceptions in the
read/write callbacks, and throw them again when control reaches back my
application, which can handle exceptions and knows what to do with them.
So in short I need to store the exception for processing at a later
time, i.e. out of the callback and within application code.
I think the same requirements hold true for any sort of callback
functions, including callbacks passed to Windows API functions, unless
the invoker specifies it is exception-safe.
Whoops! That is a __perfectly__ good reason. (Blushes, thinks "Why
didn't I think of that!?")
But! But.. That said (and, we're off-topic now), you are in the luck!
Because these MFC classes will throw exceptions by pointer, and you
can easily store it and use it elsewhere! E.g.
rettype zlib_callback(params p)
{
try
{
OperateOnMfcStuff();
}
catch(CException* p)
{
get_app_specific_data(p).mfcException = p; // You win!
}
}
Just don't use MFC exception handling macros and don't forget to
eventually call Delete() (not "delete p") on said exception pointer
( but I guess you already know this ;-) ).
Goran.
P.S. I can't effin' __believe__ that MFC has finally shown itself more
appropriate than what you would do with "normal" C++ code!