$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
From: Peter Dimov (pdimov_at_[hidden])
Date: 2005-12-08 10:39:47
Thorsten Ottosen wrote:
> Anyway, my feeling is that people that uses BOOST_NO_EXCEPTION would
> prefer
>
> if( foo() )
>  BOOST_THROW_EXCEPTION( std::exception, "MSG" );
>
> where this expands to BOOST_ASSERT( "MSG" ) when BOOST_NO_EXCEPTION
> is true.
This very much depends on foo(). In your case I suspect that foo() validates 
an input argument and the outer function is something similar to 
vector<>::at.
Think about in which circumstances one would use at() - a function that 
"recovers gracefully" from input arguments out of range by throwing an 
exception - as opposed to operator[], a function that uses BOOST_ASSERT to 
check the input.
Presumably, the client that calls at() _expects_ an exception when an out of 
range argument is passed, and this exception is handled somewhere; this 
indicates that out of range arguments to at() are expected and this code 
path forms an ordinary part of the program.
If out of range input arguments were unexpected, one would use operator[], 
possibly guarded by a user-level assert.
To get back to throw_exception, I guess my point is that nothing is gained 
by turning the throw into an assert, because people that wanted an assert 
would use the asserting function, not the throwing function.
And of course in a situation where throw_exception is used to throw 
bad_alloc, an assertion makes even less sense, because there are no "logic 
errors" involved, and presenting the effects of a failed assertion to the 
end user would serve little purpose; the program could do nothing to defend 
itself from the out of memory situation.