Home | Libraries | People | FAQ | More |
BOOST_
level
_EXCEPTION(
expression
,
exception
, predicate
)
asserts that when expression
throws an exception
of type exception
, the predicate
applied to the instance of the exception returns true
.
This is used to verify not only that an exception of the correct type was
thrown, but that the contents of the thrown exception meet the expectations
of the predicate.
The predicate
can return bool
,
or predicate_result
which allows the predicate to build up a detailed failure message.
class error_number_exception { public: error_number_exception(int num) : num_(num) { } int error_number() const { return num_; } private: int num_; }; static bool has_error_number_1(error_number_exception const& ex) { return ex.error_number() == 1; } BOOST_AUTO_TEST_CASE(example_exception) { BOOST_REQUIRE_EXCEPTION(throw error_number_exception(1), error_number_exception, has_error_number_1); }