mirror of
https://github.com/boostorg/exception.git
synced 2025-07-15 21:42:06 +02:00
added functions current_exception_cast, current_exception_diagnostic_information, various other minor changes, documentation update
[SVN r52236]
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
//Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc.
|
||||
//Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc.
|
||||
|
||||
//Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
//file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
@ -27,8 +27,8 @@ to_string( tagged_int2 const & x )
|
||||
|
||||
struct
|
||||
error1:
|
||||
public std::exception,
|
||||
public boost::exception
|
||||
std::exception,
|
||||
boost::exception
|
||||
{
|
||||
char const *
|
||||
what() const throw()
|
||||
@ -39,10 +39,42 @@ error1:
|
||||
|
||||
struct
|
||||
error2:
|
||||
public boost::exception
|
||||
boost::exception
|
||||
{
|
||||
};
|
||||
|
||||
void
|
||||
test1( std::string const & di1, std::string const & di2 )
|
||||
{
|
||||
BOOST_TEST( di1!=di2 );
|
||||
#ifndef BOOST_NO_RTTI
|
||||
BOOST_TEST(di1.find("type:")!=std::string::npos);
|
||||
BOOST_TEST(di1.find("error1")!=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);
|
||||
BOOST_TEST(di2.find("error1")!=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);
|
||||
}
|
||||
|
||||
void
|
||||
test2( std::string const & di1, std::string const & di2 )
|
||||
{
|
||||
BOOST_TEST( di1!=di2 );
|
||||
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);
|
||||
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()
|
||||
{
|
||||
@ -54,30 +86,26 @@ main()
|
||||
throw x;
|
||||
}
|
||||
catch(
|
||||
boost::exception & x )
|
||||
error1 & x )
|
||||
{
|
||||
std::string di1=boost::diagnostic_information(x);
|
||||
x << tagged_int1(2) << tagged_int2(2);
|
||||
std::string di2 = diagnostic_information(x);
|
||||
#ifndef BOOST_NO_RTTI
|
||||
BOOST_TEST(di1.find("type:")!=std::string::npos);
|
||||
BOOST_TEST(di1.find("error1")!=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);
|
||||
BOOST_TEST(di2.find("error1")!=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);
|
||||
test1(di1,di2);
|
||||
}
|
||||
try
|
||||
{
|
||||
error1 x; x << tagged_int1(42) << tagged_int2(42);
|
||||
BOOST_TEST(x.what()==std::string("error1"));
|
||||
throw x;
|
||||
}
|
||||
catch(
|
||||
... )
|
||||
error1 & x )
|
||||
{
|
||||
BOOST_TEST(false);
|
||||
std::string di1=boost::current_exception_diagnostic_information();
|
||||
x << tagged_int1(2) << tagged_int2(2);
|
||||
std::string di2 = current_exception_diagnostic_information();
|
||||
test1(di1,di2);
|
||||
}
|
||||
try
|
||||
{
|
||||
@ -86,23 +114,26 @@ main()
|
||||
throw x;
|
||||
}
|
||||
catch(
|
||||
boost::exception & x )
|
||||
error2 & x )
|
||||
{
|
||||
std::string di1 = diagnostic_information(x);
|
||||
x << tagged_int1(2) << tagged_int2(2);
|
||||
std::string di2 = diagnostic_information(x);
|
||||
BOOST_TEST( di1!=di2 );
|
||||
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);
|
||||
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);
|
||||
test2(di1,di2);
|
||||
}
|
||||
try
|
||||
{
|
||||
error2 x;
|
||||
x << tagged_int1(42) << tagged_int2(42);
|
||||
throw x;
|
||||
}
|
||||
catch(
|
||||
... )
|
||||
error2 & x )
|
||||
{
|
||||
BOOST_TEST(false);
|
||||
std::string di1 = current_exception_diagnostic_information();
|
||||
x << tagged_int1(2) << tagged_int2(2);
|
||||
std::string di2 = current_exception_diagnostic_information();
|
||||
test2(di1,di2);
|
||||
}
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
Reference in New Issue
Block a user