[Coin-discuss] CoinAssert
John J Forrest
jjforre at us.ibm.com
Mon Mar 14 10:40:47 EST 2005
There was some discussion that users may want to trap asserts so I have
extended CoinError and introduced CoinAssert, CoinAssertHint,
CoinAssertDebug and CoinAssertDebugHint. The debug versions are always
null if -DNDEBUG is given as compile option and the Hint versions contain
some hint as to what the user error might be. With the current build
options these all translate to assert. But if -DCOIN_ASSERT is given as
compile option then they throw a CoinError exception which the user can
trap.
So in Clp/Samples/addRows.cpp the code is surrounded by:
try {
..... code
}
catch (CoinError e) {
e.print();
if (e.lineNumber()>=0)
std::cout<<"This was from a CoinAssert"<<std::endl;
}
and the result is
ClpModel::1372 : assertion 'numberColumns<numberColumns_' failed.
Possible reason: rows having column indices >= numberColumns_
I have replaced some asserts in Clp by CoinAssert and will change any
others which people want changed.
CoinAssert can obviously be used by anyone. COIN_ASSERT may be made
default if optimized but it may not work with all compilers and someone
may be able to improve my #defines to give more information e.g. I don't
know how to get function name while normal assert does.
John Forrest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://list.coin-or.org/pipermail/coin-discuss/attachments/20050314/cedfbcc4/attachment.html>
More information about the Coin-discuss
mailing list