...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
BOOST_WARN_THROW(expression, exception_type); BOOST_CHECK_THROW(expression, exception_type); BOOST_REQUIRE_THROW(expression, exception_type);
These assertions validate that the execution of expression
raises an expected exception, which means an exception
of the supplied exception_type
type or of any child type.
expression
raises
an unexpected exception, this exception is not caught by BOOST_<level>_THROW
assertion and might propagate
to the test body. If not caught at all, the framework will catch it
and terminate the test case with the status failed.
expression
does
not raise any exception, the the assertion fails.
Warning | |
---|---|
the assertion catches only the expected exceptions. |
Tip | |
---|---|
It is possible to test for complex expressions with the use of constructs
such as |
Code |
---|
#define BOOST_TEST_MODULE example #include <boost/test/included/unit_test.hpp> class my_exception{}; BOOST_AUTO_TEST_CASE( test ) { int i = 0; BOOST_CHECK_THROW( i++, my_exception ); } |
Output |
---|
> example Running 1 test case... test.cpp(11): error in "test": exception my_exception is expected *** 1 failures is detected in test suite "example" |
See also: