mirror of
https://github.com/boostorg/test.git
synced 2026-01-19 16:52:11 +00:00
48 lines
1.8 KiB
Plaintext
48 lines
1.8 KiB
Plaintext
[/
|
|
/ Copyright (c) 2003-2015 Boost.Test contributors
|
|
/
|
|
/ Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
/ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
/]
|
|
|
|
|
|
[/ ################################################ ]
|
|
[section:exception_correctness Exception correctness]
|
|
|
|
Any unexpected/uncaught exception raised in the test case body will be intercepted by the Boost.test
|
|
framework and will result in the termination of the test-case with the status `failed`.
|
|
|
|
[bt_example exception_uncaught..Uncaught exception..run-fail]
|
|
|
|
More control over the exception correctness is often required, for instance to test that
|
|
an expression is raising a specific exception, intentionally.
|
|
|
|
The __UTF__ provides several assertions for testing a code with respect to the exceptions correctness.
|
|
The following assertions are available:
|
|
|
|
* __BOOST_LEVEL_NO_THROW__ checks that no exception is raised from an expression,
|
|
* __BOOST_LEVEL_THROW__ checks that an expression raises an exception of a specific type
|
|
* __BOOST_LEVEL_EXCEPTION__ checks that an expression raises an exception of a specific type,
|
|
a passes the exception instance to a predicate function for further validation (introspection
|
|
for instance)
|
|
|
|
The following example demonstrate how to use these tools to test the correct behavior of the API
|
|
of `FileWordHistogram`, in the constructor and the preconditions of the member function.
|
|
|
|
[bt_example exception_api..Exception correctness of an API..run-fail]
|
|
|
|
[note An `assert(...)` might call `abort()`: the use of the macros above may not be
|
|
suitable for testing for `assert`'s in a portable manner. ]
|
|
|
|
[h4 Bibliographic references]
|
|
|
|
[variablelist Publications
|
|
[
|
|
[[@https://isocpp.org/wiki/faq/exceptions
|
|
Exceptions and Error Handling]]
|
|
[Standard C++ Foundation]
|
|
]
|
|
]
|
|
|
|
[endsect]
|