1[/ 2 / Copyright (c) 2018 Andrey Semashev 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[section:uncaught_exceptions uncaught_exceptions] 9 10[simplesect Authors] 11 12* Andrey Semashev 13 14[endsimplesect] 15 16[section Header <boost/core/uncaught_exceptions.hpp>] 17 18The header `<boost/core/uncaught_exceptions.hpp>` defines the `boost::core::uncaught_exceptions` function, 19which is a more portable implementation of the same named function introduced in C++17. The function 20returns the number of the currently pending exceptions. When that function returns a value greater than 0, 21throwing an exception from a destructor can terminate the program. 22 23Unfortunately, the function cannot be implemented on every pre-C++17 compiler, although the most commonly 24used compilers are supported. When the compiler does not provide the necessary functionality, 25`boost::core::uncaught_exceptions` returns a non-zero value if at least one exception is pending (i.e. not 26necessarily the number of pending exceptions), and `BOOST_CORE_UNCAUGHT_EXCEPTIONS_EMULATED` macro 27is defined. 28 29[section Example] 30`` 31class my_class 32{ 33private: 34 const unsigned int m_exception_count; 35 36public: 37 my_class() : m_exception_count(boost::core::uncaught_exceptions()) 38 { 39 } 40 41 ~my_class() noexcept(false) 42 { 43 if (m_exception_count == boost::core::uncaught_exceptions()) 44 do_something_potentially_throwing(); 45 } 46}; 47`` 48[endsect] 49 50[endsect] 51 52[endsect] 53