mirror of
https://github.com/boostorg/exception.git
synced 2025-07-16 05:52:14 +02:00
New function: diagnostic_information_what.
[SVN r56448]
This commit is contained in:
@ -43,6 +43,29 @@ error2:
|
||||
{
|
||||
};
|
||||
|
||||
struct
|
||||
error3:
|
||||
std::exception
|
||||
{
|
||||
char const *
|
||||
what() const throw()
|
||||
{
|
||||
return "error3";
|
||||
}
|
||||
};
|
||||
|
||||
struct
|
||||
error4:
|
||||
std::exception,
|
||||
boost::exception
|
||||
{
|
||||
char const *
|
||||
what() const throw()
|
||||
{
|
||||
return diagnostic_information_what(*this);
|
||||
}
|
||||
};
|
||||
|
||||
void
|
||||
test1( std::string const & di1, std::string const & di2 )
|
||||
{
|
||||
@ -75,6 +98,33 @@ test2( std::string const & di1, std::string const & di2 )
|
||||
BOOST_TEST(di2.find("bad value")!=std::string::npos);
|
||||
}
|
||||
|
||||
void
|
||||
test3( std::string const & di )
|
||||
{
|
||||
#ifndef BOOST_NO_RTTI
|
||||
BOOST_TEST(di.find("type:")!=std::string::npos);
|
||||
#endif
|
||||
BOOST_TEST(di.find("error3")!=std::string::npos);
|
||||
}
|
||||
|
||||
void
|
||||
test4( std::string const & di1, std::string const & di2 )
|
||||
{
|
||||
BOOST_TEST( di1!=di2 );
|
||||
#ifndef BOOST_NO_RTTI
|
||||
BOOST_TEST(di1.find("type:")!=std::string::npos);
|
||||
#endif
|
||||
BOOST_TEST(di1.find("test_tag1")!=std::string::npos);
|
||||
BOOST_TEST(di1.find("test_tag2")!=std::string::npos);
|
||||
BOOST_TEST(di1.find("fourty-two")!=std::string::npos);
|
||||
#ifndef BOOST_NO_RTTI
|
||||
BOOST_TEST(di2.find("type:")!=std::string::npos);
|
||||
#endif
|
||||
BOOST_TEST(di2.find("test_tag1")!=std::string::npos);
|
||||
BOOST_TEST(di2.find("test_tag2")!=std::string::npos);
|
||||
BOOST_TEST(di2.find("bad value")!=std::string::npos);
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
@ -131,9 +181,58 @@ main()
|
||||
error2 & x )
|
||||
{
|
||||
std::string di1 = current_exception_diagnostic_information();
|
||||
BOOST_TEST(di1==boost::diagnostic_information_what(x));
|
||||
x << tagged_int1(2) << tagged_int2(2);
|
||||
std::string di2 = current_exception_diagnostic_information();
|
||||
BOOST_TEST(di2==boost::diagnostic_information_what(x));
|
||||
test2(di1,di2);
|
||||
}
|
||||
try
|
||||
{
|
||||
error3 x;
|
||||
std::string di=diagnostic_information(x);
|
||||
test3(di);
|
||||
throw x;
|
||||
}
|
||||
catch(
|
||||
... )
|
||||
{
|
||||
std::string di=current_exception_diagnostic_information();
|
||||
test3(di);
|
||||
}
|
||||
try
|
||||
{
|
||||
error4 x; x << tagged_int1(42) << tagged_int2(42);
|
||||
throw x;
|
||||
}
|
||||
catch(
|
||||
error4 & x )
|
||||
{
|
||||
std::string di1=boost::diagnostic_information(x);
|
||||
std::string wh1=x.what();
|
||||
BOOST_TEST(wh1==di1);
|
||||
x << tagged_int1(2) << tagged_int2(2);
|
||||
std::string di2 = diagnostic_information(x);
|
||||
std::string wh2=x.what();
|
||||
BOOST_TEST(wh2==di2);
|
||||
test4(di1,di2);
|
||||
}
|
||||
try
|
||||
{
|
||||
error4 x; x << tagged_int1(42) << tagged_int2(42);
|
||||
throw x;
|
||||
}
|
||||
catch(
|
||||
error4 & x )
|
||||
{
|
||||
std::string di1=boost::current_exception_diagnostic_information();
|
||||
std::string wh1=x.what();
|
||||
BOOST_TEST(wh1==di1);
|
||||
x << tagged_int1(2) << tagged_int2(2);
|
||||
std::string di2 = current_exception_diagnostic_information();
|
||||
std::string wh2=x.what();
|
||||
BOOST_TEST(wh2==di2);
|
||||
test4(di1,di2);
|
||||
}
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
Reference in New Issue
Block a user