mirror of
https://github.com/boostorg/throw_exception.git
synced 2025-07-12 12:06:33 +02:00
Compare commits
2 Commits
feature/te
...
feature/te
Author | SHA1 | Date | |
---|---|---|---|
26bc9374e2 | |||
a2a78f6e46 |
@ -113,14 +113,28 @@ private:
|
||||
~deleter() { delete p_; }
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
void copy_from( void const* )
|
||||
{
|
||||
}
|
||||
|
||||
void copy_from( boost::exception const* p )
|
||||
{
|
||||
static_cast<boost::exception&>( *this ) = *p;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
explicit wrapexcept( E const & e ): E( e )
|
||||
{
|
||||
copy_from( &e );
|
||||
}
|
||||
|
||||
explicit wrapexcept( E const & e, boost::source_location const & loc ): E( e )
|
||||
{
|
||||
copy_from( &e );
|
||||
|
||||
set_info( *this, throw_file( loc.file_name() ) );
|
||||
set_info( *this, throw_line( loc.line() ) );
|
||||
set_info( *this, throw_function( loc.function_name() ) );
|
||||
|
@ -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