Using the boost::test
framework, is there a way to detect if an exception (of some type) has been thrown from a function?
Asked
Active
Viewed 1,223 times
6

Elliot Cameron
- 5,235
- 2
- 27
- 34

There is nothing we can do
- 23,727
- 30
- 106
- 194
-
possible duplicate of [How do you specify that an exception should be expected using Boost.Test?](http://stackoverflow.com/questions/172854/how-do-you-specify-that-an-exception-should-be-expected-using-boost-test) – Ferruccio Nov 09 '10 at 17:59
1 Answers
7
Are you looking to test that a function correctly throws under some circumstances? If so
BOOST_CHECK_THROW( function(), exception_type );
will do it. You can use
BOOST_CHECK_EXCEPTION( function(), exception_type, predicate )
to call an arbitrary predicate on the exception when it's caught and
BOOST_CHECK_NO_THROW( function() )
to ensure a function doesn't throw.
See: http://www.boost.org/doc/libs/1_44_0/libs/test/doc/html/utf/testing-tools/reference.html

Adam Bowen
- 10,820
- 6
- 36
- 41