Test (and fix) error info with virtual inheritance from boost::exception

This commit is contained in:
Peter Dimov
2019-11-30 21:51:32 +02:00
parent c58f418c2f
commit a2a78f6e46
2 changed files with 49 additions and 0 deletions

View File

@ -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<error_code>( x );
BOOST_TEST( code != 0 );
BOOST_TEST_EQ( *code, 123 );
}
{
std::string const * str = boost::get_error_info<error_string>( 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<error_code>( x );
BOOST_TEST( code != 0 );
BOOST_TEST_EQ( *code, 123 );
}
{
std::string const * str = boost::get_error_info<error_string>( x );
BOOST_TEST( str != 0 );
BOOST_TEST_EQ( *str, "error%%string" );
}
}
return boost::report_errors();
}