From af98afb3d140c076e27fb8b1adaa1d25624982fd Mon Sep 17 00:00:00 2001 From: dmenendez-gruposantander <50944968+dmenendez-gruposantander@users.noreply.github.com> Date: Wed, 29 Jan 2020 22:41:48 +0100 Subject: [PATCH] Attempt to solve issue #10 (#24) * Attempt to solve issue #10 In boost::current_exception(), after all supported types of exception have been checked for, a boost::unknown_exception is stored in the boost::exception_ptr as a last resort to signal that an exception was indeed stored, but that the actual type and value of the exception was lost. Now, in case C++11 std::current_exception() is supported, the std::exception_ptr result of calling std::current_exception() is what gets stored inside the boost::exception_ptr. Later, inside boost::rethrow_exception, the std::exception_ptr is retrieved from the boost::exception_ptr and whatever exception it stores is thrown via std::rethrow_exception(). The main benefit is than now any exception thrown via plain 'throw' can be trasnported via boost::exception_ptr. Before this change it was required that the throw site either used boost::enable_current_exception() or boost::throw_exception() or threw an exception type inheriting from boost::exception, which was impossible for third party software that does not use Boost.Exception. The detection of std::current_exception() is currently done via config macro BOOST_NO_CXX11_NOEXCEPT, assuming that if 'noexcept' is supported then std::exception_ptr is also supported. A better solution would require a new dedicated macro in Boost.Config. * Detect support for std::current_exception() via config macro BOOST_NO_CXX11_HDR_EXCEPTION The temporary solution via BOOST_NO_CXX11_NOEXCEPT was an ugly hack that is no longer necessary now that Boost.Config has BOOST_NO_CXX11_HDR_EXCEPTION (pending merge to develop). * Attempt to solve issue #10 In boost::current_exception(), after all supported types of exception have been checked for, a boost::unknown_exception is stored in the boost::exception_ptr as a last resort to signal that an exception was indeed stored, but that the actual type and value of the exception was lost. Now, in case C++11 std::current_exception() is supported, the std::exception_ptr result of calling std::current_exception() is what gets stored inside the boost::exception_ptr. Later, inside boost::rethrow_exception, the std::exception_ptr is retrieved from the boost::exception_ptr and whatever exception it stores is thrown via std::rethrow_exception(). The main benefit is than now any exception thrown via plain 'throw' can be trasnported via boost::exception_ptr. Before this change it was required that the throw site either used boost::enable_current_exception() or boost::throw_exception() or threw an exception type inheriting from boost::exception, which was impossible for third party software that does not use Boost.Exception. The detection of std::current_exception() is currently done via config macro BOOST_NO_CXX11_NOEXCEPT, assuming that if 'noexcept' is supported then std::exception_ptr is also supported. A better solution would require a new dedicated macro in Boost.Config. * Detect support for std::current_exception() via config macro BOOST_NO_CXX11_HDR_EXCEPTION The temporary solution via BOOST_NO_CXX11_NOEXCEPT was an ugly hack that is no longer necessary now that Boost.Config has BOOST_NO_CXX11_HDR_EXCEPTION (pending merge to develop). * Document detection of C++11 std::current_exception through BOOST_NO_CXX11_HDR_EXCEPTION * Added dist: trusty for Travis config, as recommended by pdimov in issue #10 * Stupid gcc 4.7 and 4.8 are confused initializing a reference with braces, using equal sign hoping it works (tested similar code on godbolt). --- doc/current_exception.html | 2 +- .../boost/exception/detail/exception_ptr.hpp | 31 +++++ test/unknown_exception_test.cpp | 129 ++++++++++++++++++ 3 files changed, 161 insertions(+), 1 deletion(-) diff --git a/doc/current_exception.html b/doc/current_exception.html index d8b369b..b213da9 100644 --- a/doc/current_exception.html +++ b/doc/current_exception.html @@ -38,7 +38,7 @@ boost

Nothing.

Notes: