Boost logo

Boost :

From: John Torjo (john_at_[hidden])
Date: 2003-05-08 00:53:27

> I know there is this thing with macros that makes all boost macros into
> BOOST_XX, but for something
> that is widely used in "normal" code I would prefer just ASSERT. How many
> libraries/compilers will
> we clash with for this to happen? Don't MFC uses ASSERT? Anyway, couldn't
> just do something like
> #ifdef ASSERT
> #undef ASSERT
> #define ASSERT ...

Definitely, we can do that. If this is what most prefer, it's incredibly
simple to do so ;-)
However, since this ASSERT is a lot smarter, maybe it would be a good idea
to give it another name (I originally thought of SMART_ASSERT). What do you

> > 8. In case an assertion fails, an Assertion Handler will be called,
> > should ask the user whether to continue, break in code, or whatever.
> >
> > The default, will allow for:
> > - ignore
> > - ignore all
> > - abort
> > - retry (break in code)
> >
> > For Win32, I will show a message box, for other platforms, output to
> > and read from cin.
> > (or of course, the user can set its own handler, see point 4.)
> > ------------------------
> I recall that Andrei's assertion macro allowed an exception to be thrown
> instead, so you could say
> ASSERT<std::runtime_error>( "value too big", i > 0 );

Yes, indeed.
However, the way I implement it, I cannot do this (this is because it uses
<> after the macro name.

That' why I want to implement "levels".
This can be somewhat the same. I think the way I want to do it is a little
better, because usually you'll almost always want to throw
std::runtime_error - by having certain levels, it should somehow bring

For instance, setting the level to fatal_error is the same as throwing a
std::runtime_error (behind the scenes, I would throw such an error).

And of course, you can add your levels ;-)

Also, you should realize that this is still an ASSERT - it won't do anything
in release mode.

This (and from Pavel Vozenilek's suggestion, thanks Pavel!) is why I will
also allow for a BOOST_VERIFY - much like MFC's VERIFY macro - this will
behave like an ASSERT even in release mode. As a side note, using:
BOOST_VERIFY( i > 1000)(i).level(fatal_error, "i too big");
will throw even in release mode.

> or something. Shouldn't this be a feature? In this respect I would
> like to be able to compile an assertion completely away and sometimes
> I would like the opposite, that I cannot remove the assertion (and it will
> then
> throw an exception).
> > 13. Multiple levels of assertion.
> > There might be several levels of assertion.
> > The normal (default) is Debug - which, in case an assertion fails will
> > trigger a message, blabla.
> > We can have a "fatal error" level, in which case an exception could be
> > triggered.
> > For instance, we could have:
> > BOOST_ASSERT( i < 1000)(i).level( fatal_err, "value too big!");
> > --------------------------
> would there be that many levels so we couldn't just say
fatal_error( "value
> too big!" );?

I guess not. I could eventually provide "shortcuts", like:
. fatal_error( "value too big" ) equivalent to .level( fatal_error, "value
too big").


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