Boost logo

Boost :

From: David Abrahams (david.abrahams_at_[hidden])
Date: 2002-01-18 09:33:02

----- Original Message -----
From: "terekhov" <terekhov_at_[hidden]>

> > Not really. Sometimes, for example at a 'C' API boundary, you
> simply have to
> > use catch(...) so you can prevent an exception from crashing your
> caller.
> > Tom Becker has already pointed that out.
> Perhaps Tom Becker or you could clarify this issue a bit more...
> (for slowly thinking people, such as me and a couple of my
> colleagues here)

If you are writing C++ code that gets called from another language, you
generally can't let an exception propagate out of your outer-level function.
If you don't happen to know the exception, at least you can report /some/
error. If you don't catch(...), you will crash your caller unless you happen
to know (a base of) every exception type that can propagate into your

> > And, as I've pointed out, when
> > well-used, the type of an exception doesn't tell you much about
> what's
> > needed for recovery - only how to report the error
> well, the program could also, for example, change its
> further logic/processing, if something does not seem to
> work but there is one or two "workarounds".

Have you ever written a program like that? How often?
I was sure that my post at
addressed that objection, anyway. If there was something unclear about it,
please reply to it.

> > - and there are some
> > processes for which continuing to run is much more important than an
> > accurate error report.
> Perhaps we disagree on one rather simple thing - you seem
> to say that exceptions should just carry some error messages
> or so only. I think, however, that they have MEANING too;

I agree that they have meaning; they just seldom have a bearing on the
proper recovery action.

> bad_cast, for example, has REALLY BAD MEANING. Do
                              ^^^^^^ ^^^ ^^^^^^^
{You may not know this, but ALL CAPS is generally accepted as the email
equivalent of shouting. As such, frequent use of all caps is one of the
inflammatory styles of posting, I'm trying to discourage people from using
at boost. Please refrain. If you need to emphasize, you can do it like
*this*, like /this/, or like _this_, for example. Thanks -mod/dwa}

> you really want such program run your bank account? Do
> you know any program which should run just eating not
> handled bad_casts from time to time?

For any given exception type you can name, I'll say, "no, it shouldn't be
eaten - a fully descriptive error report should be generated somewhere". The
reason to catch(...) without rethrowing is to deal with the exceptions you
didn't account for. For those, the best you can do is report "an error
occurred", but for some applications, like the life support in my
spacecraft, continuing could be much better than terminating at this point.

And, BTW, bad_cast is not usually "really bad", because in general nothing
really bad has happened yet. Wwhen you use dynamic_cast, you're generally
not making assumptions about the true dynamic type of the object you're
operating on; it's a static_cast that can get you in real trouble... because
it doesn't throw.


Boost list run by bdawes at, gregod at, cpdaniel at, john at