Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2001-03-17 16:56:01


From: "David Abrahams" <abrahams_at_[hidden]>

> 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.

A _very_ simple rule that I've come up with: throw if the documentation for
the function says to throw. Assert when the documentation says undefined
behavior.

Assert-ing is a perfectly valid undefined behavior. Throwing an exception is
not - people tend to rely on it being this way.

--
Peter Dimov
Multi Media Ltd.

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk