Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BOOST_CHECK_NO_THROW how to get exception message printed

When I test a method using

BOOST_CHECK_NO_THROW( method_to_test() );

and an exception is thrown, it displays that an exception was thrown, but never the exception's message like this:

test.cpp(14): error in "test": incorrect exception my_exception is caught

Is it possible to print the exception message as well, i.e. the string returned by my_exception.what()? my_exception is derived from std::exception and overloads what().

like image 695
550 Avatar asked Feb 28 '13 10:02

550


1 Answers

I found myself annoyed by the same problem with BOOST_REQUIRE_NO_THROW. I solved it by simply removing the BOOST_REQUIRE_NO_THROW. This results in output like:

unknown location(0): fatal error in "TestName": std::runtime_error: Exception message

and aborts the test (but goes on with the next text), which is what I wanted. This doesn't help much if you wanted to use BOOST_CHECK_NO_THROW or BOOST_WARN_NO_THROW, though.

like image 62
Trebor Rude Avatar answered Nov 04 '22 05:11

Trebor Rude