1[/ 2 / Copyright (c) 2003-2015 Boost.Test contributors 3 / 4 / Distributed under the Boost Software License, Version 1.0. (See accompanying 5 / file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 /] 7 8 9[/ ################################################ ] 10[section:exception_correctness Exception correctness] 11 12Any unexpected/uncaught exception raised in the test case body will be intercepted by the Boost.test 13framework and will result in the termination of the test-case with the status `failed`. 14 15[bt_example exception_uncaught..Uncaught exception..run-fail] 16 17More control over the exception correctness is often required, for instance to test that 18an expression is raising a specific exception, intentionally. 19 20The __UTF__ provides several assertions for testing a code with respect to the exceptions correctness. 21The following assertions are available: 22 23* __BOOST_LEVEL_NO_THROW__ checks that no exception is raised from an expression, 24* __BOOST_LEVEL_THROW__ checks that an expression raises an exception of a specific type 25* __BOOST_LEVEL_EXCEPTION__ checks that an expression raises an exception of a specific type, 26 a passes the exception instance to a predicate function for further validation (introspection 27 for instance) 28 29The following example demonstrate how to use these tools to test the correct behavior of the API 30of `FileWordHistogram`, in the constructor and the preconditions of the member function. 31 32[bt_example exception_api..Exception correctness of an API..run-fail] 33 34[note An `assert(...)` might call `abort()`: the use of the macros above may not be 35 suitable for testing for `assert`'s in a portable manner. ] 36 37[h4 Bibliographic references] 38 39[variablelist Publications 40 [ 41 [[@https://isocpp.org/wiki/faq/exceptions 42 Exceptions and Error Handling]] 43 [Standard C++ Foundation] 44 ] 45] 46 47[endsect] 48