Re: How to get crash dump when a unhandled CException is thrown by a
MFC app
On Jan 8, 5:40 pm, Joseph M. Newcomer <newco...@flounder.com> wrote:
If you throw an exception that is not CException-derived, then you bypass=
the MFC handler.
Yes. I think, ideally, an MFC program should abstain from throwing
anything else. (Or, if anything else is possible, it's an error). In
fact, in general, a given piece of C++ code should only have one base
exception class. That's because one does not want catch(type1) {} catch
(unrelatedType2) all over the place, nor does one want to think about
different exception types all the time. That's one thing e.g. Java
gets better It just mandates Throwable, easy. But I had one situation
in C++, where I much enjoyed freedom to define my very own base
exception class not oming from either MFC, ATL or STL.
Luckily, one-base-exception-class is already the case, or achievable,
in MFC code. For example, AFAIK, any exception coming from standard
library is a genuine bug, so it should not happen and does not count.
Exceptions from compiler COM support can be "converted" to MFC-based
exception through a callback hook (I can dig it out, but can't
remember it now). Exceptions of third-party libraries can either
provide similar hook, or be calls to them wrapped and exceptions
rethrown as MFC exceptions. IOW, life in C++ land is full of freedom,
but hard...
I never understood why it ever made sense for the MFC dispatch loop to ca=
tch any
CException; as pointed out, the program is in an ill-defined state.
No, ill-defined state is far from a general case. Look:
BYTE b[10];
CFile(path, mode).Read(b, 10);
Here, all sorts of things that can go wrong, and will be signaled
through an exception. But there's no ill-defined state to be had. IOW,
when exceptions are used as control flow mechanism in face of
unexpected and/or rare conditions, all is fine. But when exceptions
signal code errors, it's bad. If that's the case, exception can even
do more harm than good (heck, like in this post). That's why I wrote
up there that exceptions are strictly __not__ bug-handling tool.
Goran.