
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
Peter Dimov wrote: 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. I don't think it is that simple. I've heard people saying they would like to use numeric_cast if it did not throw, but did an assertion.
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.
if that asserting function exists. it does not exists in many cases of the Pointer Container library. I think there might also be people working on platforms with exceptions who would like to get rid of the exceptions to gain a little speed. -Thorsten