2009-04-07 03:02:15 +00:00
|
|
|
//Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc.
|
2008-03-04 01:41:17 +00:00
|
|
|
|
|
|
|
//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)
|
|
|
|
|
2008-04-15 18:47:16 +00:00
|
|
|
#include <boost/exception_ptr.hpp>
|
2008-08-28 23:49:55 +00:00
|
|
|
#include <boost/exception/get_error_info.hpp>
|
2008-03-04 01:41:17 +00:00
|
|
|
#include <boost/exception/info.hpp>
|
|
|
|
#include <boost/detail/lightweight_test.hpp>
|
2008-09-22 22:47:03 +00:00
|
|
|
#include <boost/detail/workaround.hpp>
|
|
|
|
|
|
|
|
#if BOOST_WORKAROUND(__CODEGEARC__, BOOST_TESTED_AT(0x610))
|
|
|
|
struct tag_test {};
|
|
|
|
#endif
|
2008-03-04 01:41:17 +00:00
|
|
|
|
|
|
|
typedef boost::error_info<struct tag_test,int> test;
|
|
|
|
|
|
|
|
struct
|
|
|
|
test_boost_exception:
|
2008-04-08 21:29:37 +00:00
|
|
|
boost::exception
|
|
|
|
{
|
|
|
|
};
|
2008-03-04 01:41:17 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
throw_boost_exception()
|
2008-04-08 21:29:37 +00:00
|
|
|
{
|
|
|
|
throw test_boost_exception() << test(42);
|
|
|
|
}
|
2008-03-04 01:41:17 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
throw_unknown_exception()
|
2008-04-08 21:29:37 +00:00
|
|
|
{
|
|
|
|
struct
|
|
|
|
test_exception:
|
|
|
|
std::exception
|
|
|
|
{
|
|
|
|
};
|
|
|
|
throw test_exception();
|
|
|
|
}
|
2008-03-04 01:41:17 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
main()
|
2008-04-08 21:29:37 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
throw_boost_exception();
|
|
|
|
}
|
|
|
|
catch(
|
2008-04-15 18:24:46 +00:00
|
|
|
... )
|
2008-04-08 21:29:37 +00:00
|
|
|
{
|
2008-04-15 18:24:46 +00:00
|
|
|
boost::exception_ptr ep=boost::current_exception();
|
2008-04-08 21:29:37 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
rethrow_exception(ep);
|
|
|
|
}
|
|
|
|
catch(
|
|
|
|
boost::unknown_exception & x )
|
|
|
|
{
|
2009-04-06 23:15:42 +00:00
|
|
|
if( int const * d=boost::get_error_info<test>(x) )
|
2008-06-25 23:27:56 +00:00
|
|
|
BOOST_TEST( 42==*d );
|
|
|
|
else
|
|
|
|
BOOST_TEST(false);
|
2008-04-08 21:29:37 +00:00
|
|
|
}
|
|
|
|
catch(
|
2017-04-23 17:58:28 -07:00
|
|
|
boost::exception & x )
|
|
|
|
{
|
|
|
|
//Yay! Non-intrusive cloning supported!
|
|
|
|
if( int const * d=boost::get_error_info<test>(x) )
|
|
|
|
BOOST_TEST( 42==*d );
|
|
|
|
else
|
|
|
|
BOOST_TEST(false);
|
|
|
|
}
|
|
|
|
catch(
|
2008-04-15 18:24:46 +00:00
|
|
|
... )
|
|
|
|
{
|
|
|
|
BOOST_TEST(false);
|
|
|
|
}
|
|
|
|
try
|
|
|
|
{
|
|
|
|
rethrow_exception(ep);
|
|
|
|
}
|
|
|
|
catch(
|
|
|
|
boost::exception & x )
|
|
|
|
{
|
2009-04-06 23:15:42 +00:00
|
|
|
if( int const * d=boost::get_error_info<test>(x) )
|
2008-06-25 23:27:56 +00:00
|
|
|
BOOST_TEST( 42==*d );
|
|
|
|
else
|
|
|
|
BOOST_TEST(false);
|
2008-04-15 18:24:46 +00:00
|
|
|
}
|
|
|
|
catch(
|
2008-04-08 21:29:37 +00:00
|
|
|
... )
|
|
|
|
{
|
|
|
|
BOOST_TEST(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try
|
|
|
|
{
|
|
|
|
throw_unknown_exception();
|
|
|
|
}
|
|
|
|
catch(
|
2008-04-15 18:24:46 +00:00
|
|
|
... )
|
2008-04-08 21:29:37 +00:00
|
|
|
{
|
2008-04-15 18:24:46 +00:00
|
|
|
boost::exception_ptr ep=boost::current_exception();
|
2008-04-08 21:29:37 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
rethrow_exception(ep);
|
|
|
|
}
|
|
|
|
catch(
|
|
|
|
boost::unknown_exception & )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
catch(
|
2017-04-23 17:58:28 -07:00
|
|
|
std::exception & )
|
|
|
|
{
|
|
|
|
//Yay! Non-intrusive cloning supported!
|
|
|
|
}
|
|
|
|
catch(
|
2008-04-15 18:24:46 +00:00
|
|
|
... )
|
|
|
|
{
|
|
|
|
BOOST_TEST(false);
|
|
|
|
}
|
|
|
|
try
|
|
|
|
{
|
|
|
|
rethrow_exception(ep);
|
|
|
|
}
|
|
|
|
catch(
|
|
|
|
boost::exception & )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
catch(
|
2017-04-23 17:58:28 -07:00
|
|
|
std::exception & )
|
|
|
|
{
|
|
|
|
//Yay! Non-intrusive cloning supported!
|
|
|
|
}
|
|
|
|
catch(
|
2008-04-08 21:29:37 +00:00
|
|
|
... )
|
|
|
|
{
|
|
|
|
BOOST_TEST(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return boost::report_errors();
|
|
|
|
}
|