diff --git a/include/boost/throw_exception.hpp b/include/boost/throw_exception.hpp index e8fac06..0be37eb 100644 --- a/include/boost/throw_exception.hpp +++ b/include/boost/throw_exception.hpp @@ -117,10 +117,13 @@ public: explicit wrapexcept( E const & e ): E( e ) { + boost::exception_detail::copy_boost_exception( this, &e ); } explicit wrapexcept( E const & e, boost::source_location const & loc ): E( e ) { + boost::exception_detail::copy_boost_exception( this, &e ); + set_info( *this, throw_file( loc.file_name() ) ); set_info( *this, throw_line( loc.line() ) ); set_info( *this, throw_function( loc.function_name() ) ); diff --git a/test/throw_exception_test5.cpp b/test/throw_exception_test5.cpp index a4a8c43..3721333 100644 --- a/test/throw_exception_test5.cpp +++ b/test/throw_exception_test5.cpp @@ -18,6 +18,10 @@ class my_exception: public std::exception, public boost::exception { }; +class my_exception2: public std::exception, public virtual boost::exception +{ +}; + int main() { try @@ -62,5 +66,47 @@ int main() } } + try + { + boost::throw_exception( my_exception2() << error_code( 123 ) << error_string( "error%%string" ) ); + } + catch( boost::exception const & x ) + { + { + int const * code = boost::get_error_info( x ); + + BOOST_TEST( code != 0 ); + BOOST_TEST_EQ( *code, 123 ); + } + + { + std::string const * str = boost::get_error_info( x ); + + BOOST_TEST( str != 0 ); + BOOST_TEST_EQ( *str, "error%%string" ); + } + } + + try + { + BOOST_THROW_EXCEPTION( my_exception2() << error_code( 123 ) << error_string( "error%%string" ) ); + } + catch( boost::exception const & x ) + { + { + int const * code = boost::get_error_info( x ); + + BOOST_TEST( code != 0 ); + BOOST_TEST_EQ( *code, 123 ); + } + + { + std::string const * str = boost::get_error_info( x ); + + BOOST_TEST( str != 0 ); + BOOST_TEST_EQ( *str, "error%%string" ); + } + } + return boost::report_errors(); }