mirror of
https://github.com/boostorg/throw_exception.git
synced 2025-07-13 20:46:31 +02:00
Test (and fix) error info with virtual inheritance from boost::exception
This commit is contained in:
@ -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();
|
||||
}
|
||||
|
Reference in New Issue
Block a user