]>
Commit | Line | Data |
---|---|---|
92f5a8d4 TL |
1 | /* |
2 | * Copyright Andrey Semashev 2018. | |
3 | * Distributed under the Boost Software License, Version 1.0. | |
4 | * (See accompanying file LICENSE_1_0.txt or copy at | |
5 | * https://www.boost.org/LICENSE_1_0.txt) | |
6 | */ | |
7 | /*! | |
8 | * \file uncaught_exceptions.cpp | |
9 | * \author Andrey Semashev | |
10 | * \date 2018-11-10 | |
11 | * | |
12 | * \brief This file contains tests for the uncaught_exceptions function. | |
13 | * | |
14 | * This file only contains the very basic checks of functionality that can be portably achieved | |
15 | * through C++03 std::uncaught_exception. | |
16 | */ | |
17 | ||
18 | #include <boost/core/uncaught_exceptions.hpp> | |
19 | #include <boost/core/lightweight_test.hpp> | |
20 | ||
1e59de90 TL |
21 | #if defined(_MSC_VER) |
22 | # pragma warning(disable: 4512) // assignment operator could not be generated | |
23 | #endif | |
24 | ||
92f5a8d4 TL |
25 | struct my_exception {}; |
26 | ||
27 | class exception_watcher | |
28 | { | |
29 | unsigned int& m_count; | |
30 | ||
31 | public: | |
32 | explicit exception_watcher(unsigned int& count) : m_count(count) {} | |
33 | ~exception_watcher() { m_count = boost::core::uncaught_exceptions(); } | |
34 | }; | |
35 | ||
36 | // Tests for uncaught_exceptions when used in a destructor while an exception propagates | |
37 | void test_in_destructor() | |
38 | { | |
39 | const unsigned int root_count = boost::core::uncaught_exceptions(); | |
40 | ||
41 | unsigned int level1_count = root_count; | |
42 | try | |
43 | { | |
44 | exception_watcher watcher(level1_count); | |
45 | throw my_exception(); | |
46 | } | |
47 | catch (...) | |
48 | { | |
49 | } | |
50 | ||
51 | BOOST_TEST_NE(root_count, level1_count); | |
52 | } | |
53 | ||
54 | int main() | |
55 | { | |
56 | test_in_destructor(); | |
57 | ||
58 | return boost::report_errors(); | |
59 | } |