Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2001-04-11 10:58:20


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

> As I have previously posted, throwing an exception in place of an
assertion
> can make misuse much harder to debug. An assertion stops the program at
the
> point of the violation without changing its state, often producing a core
> dump or other information which can be used to look at the program state
in
> a debugger. An exception causes stack unwinding and other reactions which
> can obscure the cause of the problem.

Yes, I see the point, but

* some debuggers can break on throw.
* you can assert(f); before calling f() if you like; and I would, because
(1) I have absolutely no guarantee that the documented "undefined behavior"
will assert, (2) this makes it clear for the reader that f is not allowed to
be empty, and (3) my own 'assert' does some additional things, like
restoring the display mode.

(1) and (3) can be addressed by documenting that f() calls
boost::precondition_violation(EMPTY_FUNCTION) when f is empty, where
boost::precondition_violation can be overriden by the user. But this is not
'undefined behavior.' It's a well defined behavior that does not throw, but
still checks for misuse.

> It comes down to a question of definitions: is passing a 0 to the
> constructor misuse, or is it allowed? If it's misuse I want an assertion.

A default constructed function is most certainly not a misuse, although I'm
not sure whether this is an answer to your question.

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