support for exception_ptr and nesting of exception_ptr objects in boost::diagnostic_information

[SVN r53066]
This commit is contained in:
Emil Dotchevski
2009-05-17 06:12:29 +00:00
parent 4138359063
commit de1a3daa85
47 changed files with 7227 additions and 6549 deletions

View File

@ -5,7 +5,6 @@
#include <boost/exception_ptr.hpp>
#include <boost/exception/get_error_info.hpp>
#include <boost/exception/info.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <boost/detail/workaround.hpp>
#include <string>
@ -14,6 +13,8 @@
struct my_tag {};
#endif
typedef boost::error_info<struct nested_exception_tag,boost::exception_ptr> nested_exception;
typedef boost::error_info<struct my_tag,int> my_info;
template <class T>
@ -70,6 +71,17 @@ derives_std_boost_exception:
std::exception,
boost::exception
{
char const * const wh_;
derives_std_boost_exception( char const * wh="derives_std_boost_exception" ):
wh_(wh)
{
}
char const * what() const throw()
{
return wh_;
}
};
struct
@ -121,6 +133,24 @@ test_std_exception()
}
}
catch(
... )
{
BOOST_TEST(false);
}
try
{
rethrow_exception(p);
BOOST_TEST(false);
}
catch(
boost::exception & x )
{
#ifndef BOOST_NO_RTTI
std::type_info const * const * t=boost::get_error_info<boost::original_exception_type>(x);
BOOST_TEST(t!=0 && *t!=0 && **t==typeid(T));
#endif
}
catch(
... )
{
BOOST_TEST(false);
@ -173,6 +203,24 @@ test_std_exception_what()
}
}
catch(
... )
{
BOOST_TEST(false);
}
try
{
rethrow_exception(p);
BOOST_TEST(false);
}
catch(
boost::exception & x )
{
#ifndef BOOST_NO_RTTI
std::type_info const * const * t=boost::get_error_info<boost::original_exception_type>(x);
BOOST_TEST(t!=0 && *t!=0 && **t==typeid(T));
#endif
}
catch(
... )
{
BOOST_TEST(false);
@ -342,8 +390,12 @@ main()
BOOST_TEST(false);
}
catch(
boost::unknown_exception & )
boost::unknown_exception & e )
{
#ifndef BOOST_NO_RTTI
std::type_info const * const * t=boost::get_error_info<boost::original_exception_type>(e);
BOOST_TEST(t!=0 && *t!=0 && **t==typeid(derives_std_exception));
#endif
}
catch(
... )
@ -352,15 +404,23 @@ main()
}
}
test_std_exception_what<std::domain_error>();
test_std_exception_what<std::invalid_argument>();
test_std_exception_what<std::length_error>();
test_std_exception_what<std::out_of_range>();
test_std_exception_what<std::logic_error>();
test_std_exception_what<std::range_error>();
test_std_exception_what<std::overflow_error>();
test_std_exception_what<std::underflow_error>();
test_std_exception_what<std::ios_base::failure>();
test_std_exception_what<std::runtime_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>();
test_std_exception<std::exception>();
try
{
@ -384,6 +444,12 @@ main()
BOOST_TEST(boost::get_error_info<my_info>(x));
if( int const * p=boost::get_error_info<my_info>(x) )
BOOST_TEST(*p==42);
#ifndef BOOST_NO_RTTI
{
std::type_info const * const * t=boost::get_error_info<boost::original_exception_type>(x);
BOOST_TEST(t && *t && **t==typeid(derives_std_boost_exception));
}
#endif
boost::exception_ptr p = boost::current_exception();
BOOST_TEST(!(p==boost::exception_ptr()));
BOOST_TEST(p!=boost::exception_ptr());
@ -399,6 +465,10 @@ main()
BOOST_TEST(boost::get_error_info<my_info>(x));
if( int const * p=boost::get_error_info<my_info>(x) )
BOOST_TEST(*p==42);
#ifndef BOOST_NO_RTTI
std::type_info const * const * t=boost::get_error_info<boost::original_exception_type>(x);
BOOST_TEST(t && *t && **t==typeid(derives_std_boost_exception));
#endif
}
catch(
... )
@ -435,6 +505,12 @@ main()
BOOST_TEST(boost::get_error_info<my_info>(x));
if( int const * p=boost::get_error_info<my_info>(x) )
BOOST_TEST(*p==42);
#ifndef BOOST_NO_RTTI
{
std::type_info const * const * t=boost::get_error_info<boost::original_exception_type>(x);
BOOST_TEST(t && *t && **t==typeid(derives_boost_exception));
}
#endif
boost::exception_ptr p = boost::current_exception();
BOOST_TEST(!(p==boost::exception_ptr()));
BOOST_TEST(p!=boost::exception_ptr());
@ -467,5 +543,30 @@ main()
test_throw_on_copy<std::bad_alloc,std::bad_alloc>();
test_throw_on_copy<int,std::bad_exception>();
try
{
throw boost::enable_current_exception(derives_std_boost_exception("what1"));
}
catch(
... )
{
boost::exception_ptr p=boost::current_exception();
{
std::string s=diagnostic_information(p);
BOOST_TEST(s.find("what1")!=s.npos);
}
try
{
throw boost::enable_current_exception(derives_std_boost_exception("what2") << nested_exception(p) );
}
catch(
... )
{
std::string s=boost::current_exception_diagnostic_information();
BOOST_TEST(s.find("what1")!=s.npos);
BOOST_TEST(s.find("what2")!=s.npos);
}
}
BOOST_TEST(!diagnostic_information(boost::exception_ptr()).empty());
return boost::report_errors();
}