Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for a snapshot of the develop branch, built from commit 549cd0dc90.
PrevUpHomeNext

uncaught_exceptions

Header <boost/core/uncaught_exceptions.hpp>

Authors

  • Andrey Semashev

The header <boost/core/uncaught_exceptions.hpp> defines the boost::core::uncaught_exceptions function, which is a more portable implementation of the same named function introduced in C++17. The function returns the number of the currently pending exceptions. When that function returns a value greater than 0, throwing an exception from a destructor can terminate the program.

Unfortunately, the function cannot be implemented on every pre-C++17 compiler, although the most commonly used compilers are supported. When the compiler does not provide the necessary functionality, boost::core::uncaught_exceptions returns a non-zero value if at least one exception is pending (i.e. not necessarily the number of pending exceptions), and BOOST_CORE_UNCAUGHT_EXCEPTIONS_EMULATED macro is defined.

class my_class
{
private:
    const unsigned int m_exception_count;

public:
    my_class() : m_exception_count(boost::core::uncaught_exceptions())
    {
    }

    ~my_class() noexcept(false)
    {
        if (m_exception_count == boost::core::uncaught_exceptions())
            do_something_potentially_throwing();
    }
};

PrevUpHomeNext