|
Boost : |
From: williamkempf_at_[hidden]
Date: 2001-03-18 08:35:30
--- In boost_at_y..., "David Abrahams" <abrahams_at_m...> wrote:
> IMO using the question "is this an exceptional situation?" to
decide whether
> to throw an exception has an attractive ring to it, but is usually a
> mistake. A more appropriate question to ask is: "do we want stack
unwinding
> here?"
>
> As a developer, if I have violated a precondition of a library I'm
using, I
> don't want stack unwinding. What I want is a core dump or the
equivalent - a
> way to inspect the state of the program at the point where the
problem was
> detected. That usually means assert() or some equivalent.
>
> I have sympathy with the idea of making resilient APIs which can
stand up to
> nearly any kind of client abuse, but there is usually a significant
cost to
> this approach. If someone wants that sort of protection, it can
usually be
> provided as a layer on top of a simpler API. I am utterly
unsympathetic to
> half-measures, though. An API which promises resilience against
some, but
> not all abuse is an invitation to disaster.
An assertion would be just such a disaster. I understand what you're
saying here, but the exception seems like the only viable solution in
this situation to me. Assertions will miss a large class of errors,
since they'll be off when you really need them. Error code returns
would be even worse. If there were another option it might be worth
considering.
Bill Kempf
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk