BOOST_WARN_THROW( statement, exception )
BOOST_CHECK_THROW( statement, exception )
BOOST_REQUIRE_THROW( statement, exception )

These tools are used to perform an exception detection check. Tools execute the supplied statement and checks that it throws the supplied exception or it's child. If the statement throw any other unrelated exception or doesn't throw at all, check fails.

If check is successful, the tool produces a confirmation message, in other case it produces an error message in a form "error in <test case name>: exception <exception> expected.

The first parameter is the statement to execute. Use block statement if you want to execute more than one statement. The second parameter is an expected exception.

Example: test.cpp

#include <boost/test/unit_test.hpp>
class my_exception{}; BOOST_AUTO_TEST_CASE( test ) { int i = 0; BOOST_CHECK_THROW( i++, my_exception ); }


Running 1 test case...
test.cpp(9): error in "test": exception my_exception is expected

*** 1 failure detected in test suite "Master Test Suite"

See Also