mirror of
https://github.com/boostorg/exception.git
synced 2025-07-29 03:57:18 +02:00
decoupled boost/exception/exception.hpp from boost/exception/detail/type_info.hpp
diagnostic_information improvements documentation update [SVN r48469]
This commit is contained in:
@ -351,8 +351,10 @@ main()
|
||||
test_std_exception_what<std::out_of_range>();
|
||||
test_std_exception_what<std::logic_error>();
|
||||
test_std_exception<std::bad_alloc>();
|
||||
#ifndef BOOST_NO_TYPEID
|
||||
test_std_exception<std::bad_cast>();
|
||||
test_std_exception<std::bad_typeid>();
|
||||
#endif
|
||||
test_std_exception<std::bad_exception>();
|
||||
|
||||
try
|
||||
|
@ -38,12 +38,6 @@ error3:
|
||||
{
|
||||
};
|
||||
|
||||
std::string
|
||||
get_diagnostic_information( std::exception const & x )
|
||||
{
|
||||
return boost::diagnostic_information(x);
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
@ -57,7 +51,7 @@ main()
|
||||
catch(
|
||||
std::exception & x )
|
||||
{
|
||||
std::string di=get_diagnostic_information(x);
|
||||
std::string di=boost::diagnostic_information(x);
|
||||
BOOST_TEST(di.find("type:")!=std::string::npos);
|
||||
BOOST_TEST(di.find("error1")!=std::string::npos);
|
||||
}
|
||||
@ -75,11 +69,26 @@ main()
|
||||
catch(
|
||||
std::exception & x )
|
||||
{
|
||||
std::string di=get_diagnostic_information(x);
|
||||
std::string di=boost::diagnostic_information(x);
|
||||
BOOST_TEST(di.find("type:")!=std::string::npos);
|
||||
#ifndef BOOST_NO_RTTI
|
||||
BOOST_TEST(di.find("error2")!=std::string::npos);
|
||||
#endif
|
||||
}
|
||||
catch(
|
||||
... )
|
||||
{
|
||||
BOOST_TEST(false);
|
||||
}
|
||||
try
|
||||
{
|
||||
error2 x; x << tag_int(42);
|
||||
BOOST_TEST(x.what()==std::string("error2"));
|
||||
throw x;
|
||||
}
|
||||
catch(
|
||||
boost::exception & x )
|
||||
{
|
||||
std::string di=boost::diagnostic_information(x);
|
||||
BOOST_TEST(di.find("type:")!=std::string::npos);
|
||||
BOOST_TEST(di.find("test_tag")!=std::string::npos);
|
||||
}
|
||||
catch(
|
||||
@ -96,9 +105,9 @@ main()
|
||||
catch(
|
||||
boost::exception & x )
|
||||
{
|
||||
std::string w1 = x.diagnostic_information();
|
||||
std::string w1 = diagnostic_information(x);
|
||||
x << tag_int(2);
|
||||
std::string w2 = x.diagnostic_information();
|
||||
std::string w2 = diagnostic_information(x);
|
||||
BOOST_TEST( w1!=w2 );
|
||||
BOOST_TEST(w1.find("test_tag")!=std::string::npos);
|
||||
BOOST_TEST(w2.find("test_tag")!=std::string::npos);
|
||||
|
@ -45,7 +45,26 @@ main()
|
||||
catch(
|
||||
std::exception & x )
|
||||
{
|
||||
BOOST_TEST( 42==*boost::get_error_info<test_int>(x) );
|
||||
#ifdef BOOST_NO_RTTI
|
||||
try
|
||||
{
|
||||
throw;
|
||||
}
|
||||
catch(
|
||||
boost::exception & x )
|
||||
{
|
||||
#endif
|
||||
BOOST_TEST( boost::get_error_info<test_int>(x) );
|
||||
if( boost::shared_ptr<int const> p=boost::get_error_info<test_int>(x) )
|
||||
BOOST_TEST( 42==*p );
|
||||
#ifdef BOOST_NO_RTTI
|
||||
}
|
||||
catch(
|
||||
... )
|
||||
{
|
||||
BOOST_TEST(false);
|
||||
}
|
||||
#endif
|
||||
BOOST_TEST( std::string(x.what())==std::string("exception test length error") );
|
||||
}
|
||||
catch(
|
||||
|
@ -10,12 +10,37 @@
|
||||
struct throws_on_copy;
|
||||
struct non_printable { };
|
||||
|
||||
struct
|
||||
user_data
|
||||
{
|
||||
int & count;
|
||||
|
||||
explicit
|
||||
user_data( int & count ):
|
||||
count(count)
|
||||
{
|
||||
++count;
|
||||
}
|
||||
|
||||
user_data( user_data const & x ):
|
||||
count(x.count)
|
||||
{
|
||||
++count;
|
||||
}
|
||||
|
||||
~user_data()
|
||||
{
|
||||
--count;
|
||||
}
|
||||
};
|
||||
|
||||
typedef boost::error_info<struct tag_test_1,int> test_1;
|
||||
typedef boost::error_info<struct tag_test_2,unsigned int> test_2;
|
||||
typedef boost::error_info<struct tag_test_3,float> test_3;
|
||||
typedef boost::error_info<struct tag_test_4,throws_on_copy> test_4;
|
||||
typedef boost::error_info<struct tag_test_5,std::string> test_5;
|
||||
typedef boost::error_info<struct tag_test_6,non_printable> test_6;
|
||||
typedef boost::error_info<struct tag_user_data,user_data> test_7;
|
||||
|
||||
struct
|
||||
test_exception:
|
||||
@ -135,7 +160,9 @@ test_empty()
|
||||
catch(
|
||||
test_exception & x )
|
||||
{
|
||||
BOOST_TEST( boost::exception_detail::get_boost_exception(&x) );
|
||||
#ifndef BOOST_NO_RTTI
|
||||
BOOST_TEST( dynamic_cast<boost::exception const *>(&x)!=0 );
|
||||
#endif
|
||||
}
|
||||
catch(
|
||||
... )
|
||||
@ -256,6 +283,29 @@ test_add_tuple()
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
test_lifetime()
|
||||
{
|
||||
int count=0;
|
||||
try
|
||||
{
|
||||
throw test_exception() << test_7(user_data(count));
|
||||
BOOST_TEST(false);
|
||||
}
|
||||
catch(
|
||||
boost::exception & x )
|
||||
{
|
||||
BOOST_TEST(count==1);
|
||||
BOOST_TEST( boost::get_error_info<test_7>(x) );
|
||||
}
|
||||
catch(
|
||||
... )
|
||||
{
|
||||
BOOST_TEST(false);
|
||||
}
|
||||
BOOST_TEST(!count);
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
@ -265,5 +315,6 @@ main()
|
||||
test_basic_throw_catch();
|
||||
test_catch_add_info();
|
||||
test_add_tuple();
|
||||
test_lifetime();
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
@ -47,9 +47,26 @@ tester()
|
||||
catch(
|
||||
T & y )
|
||||
{
|
||||
BOOST_TEST(boost::get_error_info<test_data>(y));
|
||||
if( boost::shared_ptr<int const> d=boost::get_error_info<test_data>(y) )
|
||||
BOOST_TEST(*d==42);
|
||||
#ifdef BOOST_NO_RTTI
|
||||
try
|
||||
{
|
||||
throw;
|
||||
}
|
||||
catch(
|
||||
boost::exception & y )
|
||||
{
|
||||
#endif
|
||||
BOOST_TEST(boost::get_error_info<test_data>(y));
|
||||
if( boost::shared_ptr<int const> d=boost::get_error_info<test_data>(y) )
|
||||
BOOST_TEST(*d==42);
|
||||
#ifdef BOOST_NO_RTTI
|
||||
}
|
||||
catch(
|
||||
... )
|
||||
{
|
||||
BOOST_TEST(false);
|
||||
}
|
||||
#endif
|
||||
BOOST_TEST(y.x_==42);
|
||||
}
|
||||
catch(
|
||||
|
Reference in New Issue
Block a user