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)
|
|
|
|
|
|
2020-12-22 17:26:53 -08:00
|
|
|
#include <boost/config.hpp>
|
|
|
|
|
|
|
|
|
|
#if defined( BOOST_NO_EXCEPTIONS )
|
|
|
|
|
# error This program requires exception handling.
|
|
|
|
|
#endif
|
|
|
|
|
|
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>
|
|
|
|
|
|
2020-04-30 17:26:21 -04:00
|
|
|
#if BOOST_WORKAROUND(BOOST_CODEGEARC, BOOST_TESTED_AT(0x610))
|
2008-09-22 22:47:03 +00:00
|
|
|
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
|
|
|
|
2020-01-29 22:41:48 +01:00
|
|
|
struct
|
|
|
|
|
user_defined_exception
|
|
|
|
|
{
|
|
|
|
|
user_defined_exception(int d):data(d){}
|
|
|
|
|
int data;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
throw_user_defined_exception()
|
|
|
|
|
{
|
|
|
|
|
throw user_defined_exception(42);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
throw_builtin_exception()
|
|
|
|
|
{
|
|
|
|
|
throw 42;
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-01-29 22:41:48 +01:00
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
throw_user_defined_exception();
|
|
|
|
|
}
|
|
|
|
|
catch(
|
|
|
|
|
... )
|
|
|
|
|
{
|
|
|
|
|
boost::exception_ptr ep=boost::current_exception();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
rethrow_exception(ep);
|
|
|
|
|
}
|
|
|
|
|
#ifndef BOOST_NO_CXX11_HDR_EXCEPTION
|
|
|
|
|
catch(
|
|
|
|
|
user_defined_exception & x)
|
|
|
|
|
{
|
|
|
|
|
//Yay! std::current_exception to the rescue!
|
|
|
|
|
BOOST_TEST( 42==x.data );
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
catch(
|
|
|
|
|
boost::unknown_exception & )
|
|
|
|
|
{
|
|
|
|
|
//Boo! user defined exception was transported as a boost::unknown_exception
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
catch(
|
|
|
|
|
... )
|
|
|
|
|
{
|
|
|
|
|
BOOST_TEST(false);
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
rethrow_exception(ep);
|
|
|
|
|
}
|
|
|
|
|
#ifndef BOOST_NO_CXX11_HDR_EXCEPTION
|
|
|
|
|
catch(
|
|
|
|
|
user_defined_exception & x)
|
|
|
|
|
{
|
|
|
|
|
//Yay! std::current_exception to the rescue!
|
|
|
|
|
BOOST_TEST( 42==x.data );
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
catch(
|
|
|
|
|
boost::unknown_exception & )
|
|
|
|
|
{
|
|
|
|
|
//Boo! user defined exception was transported as a boost::unknown_exception
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
catch(
|
|
|
|
|
... )
|
|
|
|
|
{
|
|
|
|
|
BOOST_TEST(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
throw_builtin_exception();
|
|
|
|
|
}
|
|
|
|
|
catch(
|
|
|
|
|
... )
|
|
|
|
|
{
|
|
|
|
|
boost::exception_ptr ep=boost::current_exception();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
rethrow_exception(ep);
|
|
|
|
|
}
|
|
|
|
|
#ifndef BOOST_NO_CXX11_HDR_EXCEPTION
|
|
|
|
|
catch(
|
|
|
|
|
int & x)
|
|
|
|
|
{
|
|
|
|
|
//Yay! std::current_exception to the rescue!
|
|
|
|
|
BOOST_TEST( 42==x );
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
catch(
|
|
|
|
|
boost::unknown_exception & )
|
|
|
|
|
{
|
|
|
|
|
//Boo! builtin exception was transported as a boost::unknown_exception
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
catch(
|
|
|
|
|
... )
|
|
|
|
|
{
|
|
|
|
|
BOOST_TEST(false);
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
rethrow_exception(ep);
|
|
|
|
|
}
|
|
|
|
|
#ifndef BOOST_NO_CXX11_HDR_EXCEPTION
|
|
|
|
|
catch(
|
|
|
|
|
int & x)
|
|
|
|
|
{
|
|
|
|
|
//Yay! std::current_exception to the rescue!
|
|
|
|
|
BOOST_TEST( 42==x );
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
catch(
|
|
|
|
|
boost::unknown_exception & )
|
|
|
|
|
{
|
|
|
|
|
//Boo! builtin exception was transported as a boost::unknown_exception
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
catch(
|
|
|
|
|
... )
|
|
|
|
|
{
|
|
|
|
|
BOOST_TEST(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-04-08 21:29:37 +00:00
|
|
|
return boost::report_errors();
|
|
|
|
|
}
|