Boost logo

Boost :

From: David Abrahams (abrahams_at_[hidden])
Date: 2001-04-11 12:09:37


----- Original Message -----
From: "Peter Dimov" <pdimov_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Wednesday, April 11, 2001 11:58 AM
Subject: Re: [boost] any_function (callback) library

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

I'm talking about JIT debugging: when you're running outside the debugger,
the program asserts, and the debugger pops up.

Also, there are circumstances (especially during testing of error-handling)
when exceptions happen a fairly significant percentage of the time. You
don't want to stop for every exception, but you need to stop immediately
when there is an assert.

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

Yep, that would handle it.

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

It is, but I asked the wrong question by mistake. ;-)

-Dave


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