mirror of
https://github.com/boostorg/exception.git
synced 2025-07-20 07:52:07 +02:00
mutable get_error_info support
[SVN r55707]
This commit is contained in:
@ -30,15 +30,19 @@ main()
|
||||
using namespace boost;
|
||||
try
|
||||
{
|
||||
BOOST_THROW_EXCEPTION(
|
||||
test_exception() <<
|
||||
test_exception e;
|
||||
e <<
|
||||
errinfo_api_function("failed_api_function") <<
|
||||
errinfo_at_line(42) <<
|
||||
errinfo_errno(errno) <<
|
||||
errinfo_file_handle(weak_ptr<FILE>()) <<
|
||||
errinfo_file_name("filename.txt") <<
|
||||
errinfo_file_open_mode("rb") <<
|
||||
errinfo_type_info_name(typeid(int).name()) );
|
||||
errinfo_file_open_mode("rb");
|
||||
#ifdef BOOST_NO_TYPEID
|
||||
BOOST_THROW_EXCEPTION(e);
|
||||
#else
|
||||
BOOST_THROW_EXCEPTION(e<<errinfo_type_info_name(typeid(int).name()));
|
||||
#endif
|
||||
BOOST_TEST(false);
|
||||
}
|
||||
catch(
|
||||
@ -50,7 +54,9 @@ main()
|
||||
BOOST_TEST(get_error_info<errinfo_file_handle>(e) && get_error_info<errinfo_file_handle>(e)->expired());
|
||||
BOOST_TEST(get_error_info<errinfo_file_name>(e) && *get_error_info<errinfo_file_name>(e)=="filename.txt");
|
||||
BOOST_TEST(get_error_info<errinfo_file_open_mode>(e) && *get_error_info<errinfo_file_open_mode>(e)=="rb");
|
||||
#ifndef BOOST_NO_TYPEID
|
||||
BOOST_TEST(get_error_info<errinfo_type_info_name>(e) && *get_error_info<errinfo_type_info_name>(e)==typeid(int).name());
|
||||
#endif
|
||||
}
|
||||
catch(
|
||||
... )
|
||||
|
@ -83,6 +83,23 @@ basic_test()
|
||||
}
|
||||
catch(
|
||||
test_exception & x )
|
||||
{
|
||||
++*boost::get_error_info<test_1>(x);
|
||||
++*boost::get_error_info<test_2>(x);
|
||||
++*boost::get_error_info<test_3>(x);
|
||||
BOOST_TEST(*boost::get_error_info<test_1>(x)==2);
|
||||
BOOST_TEST(*boost::get_error_info<test_2>(x)==3u);
|
||||
BOOST_TEST(*boost::get_error_info<test_3>(x)==4.14159f);
|
||||
BOOST_TEST(!boost::get_error_info<test_4>(x));
|
||||
}
|
||||
try
|
||||
{
|
||||
test_exception x;
|
||||
x << test_1(1) << test_2(2u) << test_3(3.14159f);
|
||||
throw x;
|
||||
}
|
||||
catch(
|
||||
test_exception const & x )
|
||||
{
|
||||
BOOST_TEST(*boost::get_error_info<test_1>(x)==1);
|
||||
BOOST_TEST(*boost::get_error_info<test_2>(x)==2u);
|
||||
@ -317,6 +334,28 @@ test_lifetime()
|
||||
BOOST_TEST(!count);
|
||||
}
|
||||
|
||||
bool
|
||||
is_const( int const * )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
is_const( int * )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
test_const()
|
||||
{
|
||||
test_exception e;
|
||||
boost::exception const & c(e);
|
||||
boost::exception & m(e);
|
||||
BOOST_TEST(is_const(boost::get_error_info<test_1>(c)));
|
||||
BOOST_TEST(!is_const(boost::get_error_info<test_1>(m)));
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
@ -327,5 +366,6 @@ main()
|
||||
test_catch_add_info();
|
||||
test_add_tuple();
|
||||
test_lifetime();
|
||||
test_const();
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
Reference in New Issue
Block a user