Boost logo

Boost :

From: Toon Knapen (toon.knapen_at_[hidden])
Date: 2001-11-12 08:41:24

Peter Dimov wrote:

> See the code at the end for my proposed implementation of BOOST_ASSERT.
> Design goals:
> * Simple;
> * Off by default;
> * User customizable.
> Modes of operation include:
> 1. off; when BOOST_DEBUG is not defined.
> 2. simply use assert(); with -DBOOST_DEBUG and -DBOOST_ASSERT=assert.
> 3. invoke user error handler (boost_error), then assert();
> 3a. log error and throw.
> 3b. log error and continue.
> 3c. log error and assert().
> 3d. log error and terminate (whole process or current thread only.)
> 3e. perform cleanup and assert().
> etc.
> Comments?

On C99 compatible compilers you can also indicate the function in which
the assert occured using __func__ (in addition to __LINE__ and __FILE__)
(e.g. gcc-2.95.x and newer do this in their assert)

Ideally would also be to have a stacktrace-dump when an assert occurs
(and the user would want this). The only way I see to do this is to
insert in debug-mode a small object in every function which is going to
register the function in a stack in some singleton (using __func__). If
the program aborts, you thus print the content of the stack in the
singleton to std::cerr. However, some might find this to intrusive ?


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