....
* C++: I believe the "clown" comment was aimed at throwing pointers to
dynamically allocated objects.
I disagree. "delete this" fragment was brought up by the commenter (see
above), it was not in the original post.
It's a recipe for disaster, because of
the lack of designated owner and possibility of "catch(...)". U
In general, it is a recipe for a memory leak (whether a memory leak is
always and patently a disaster is a different matter). In particular,
when only structured exceptions (thrown by the underlying C API we do
not control) are processed by throwing a pointer to an exception and all
such exceptions have a common base class (in the example, CSeException),
it seems acceptable to me (and will not create a memory leak). I am just
trying to keep in mind the original problem: processing Windows
sructured exceptions in C++ code.
"delete this", on the other hand, is a normal way to do destruction in
many situations, nothing wrong with that, although it is a power tool
that can be dangerous in untrained hands.
Completely agree.
* Windows: structured exception handling (SEH) is an operation system
API way to communicate failure that targets no specific language, but
does require language support. Most of it is undocumented. As I recall
Matt Pietrik (not sure of speling) wrote a series of articles going into
depth of the undocumented aspects, including typical language support.
Well, it is documented in the enough details to catch them in C. "No
specific language" is correct for the exception client but not for the
code that raises exception (it is C API, after all).
Language support (beyond setjmp()/longjmp() support which would
introduce platform dependency anyway, by C standard) was not really
required to solve the problem, it was just usual old Microsoft's way of
presenting their facilities in the most nonstandard way possible.
* MFC exceptions (MFC is an old C++ GUI framework from Microsoft):
throwing pointers had, as far as I know, nothing to do with SEH, and
these exceptions were not targeted at C, since MFC was and is a C++
class framework.
Well that's where I would partly disagree. What you are saying is a
possibility but why exactly Microsoft introduced this "MFC standard way"
of throwing will probably stay unknown forever. Theoretically it is
possible it did not have anything to do with SEH but it is obvious to me
that unconditionally leaving the destruction of the exception
information up to the exception handler is so consistent with the
structured exceptions and old C ways (again, I heard your "no specific
language" but ? was the primary API target and implementation language
(with some assembler) so I would not bet much on that.
But it is all misses the point (almost). The reason why I mentioned the
MFC exception is because the code in the question took MFC base
exception to handle Windows structured exceptions (even though the did
not have to do it):
class CSeException : public CException
{
....
and then the followed the regular MFC practice of throwing the pointers.
The resulting code and suggested framework seem reasonably save to me as
long as the users will use MFC conventions consistently (which they will
have trouble not to do anyway as the solution introduces dependencies on
MFC).
....
Of course, this mess is on its own a good reason not to use MFC... ;-)
Agree, I never liked MFC myself. Even now I use C API on Windows --
"When in Rome .." -- and AFAIK "Romans" do not use MFC for their killer
apps -- or maybe they do now but before they did not.
-Pavel