BOOST_CHECK_THROW( statement, exception )

This tool is used to perform an exception detection check. The tool executes 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 (note: to manage what messages appear in the test output stream set the proper log level), in other case it produces an error message in a form "error in <test case name>: exception <exception> expected.

The tool's first parameter is the statement to execute while checking for exception. Use block statement if you want to execute more than one statement. The tool's second parameter is an expected exception.

Example: test.cpp

class my_exception{};
int test_main( int, char* [] ) {
    int i =  0;
    BOOST_CHECK_THROW( i++, my_exception );
    return 0;


test.cpp(4) : error in test_main: exception my_exception expected

See Also