mirror of
https://github.com/boostorg/exception.git
synced 2025-07-02 07:21:05 +02:00
Boost Exception major refactoring: works with or without RTTI, vastly improved boost::throw_exception integration.
[SVN r48905]
This commit is contained in:
@ -4,12 +4,73 @@
|
||||
//file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include "helper2.hpp"
|
||||
#include <boost/exception/get_error_info.hpp>
|
||||
#include <boost/exception/info.hpp>
|
||||
#include <boost/exception_ptr.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
typedef boost::error_info<struct tag_test_int,int> test_data;
|
||||
|
||||
struct
|
||||
exception1:
|
||||
std::exception
|
||||
{
|
||||
};
|
||||
|
||||
struct
|
||||
exception2:
|
||||
std::exception,
|
||||
boost::exception
|
||||
{
|
||||
};
|
||||
|
||||
void
|
||||
boost_throw_exception_test()
|
||||
{
|
||||
try
|
||||
{
|
||||
BOOST_THROW_EXCEPTION(exception1());
|
||||
BOOST_TEST(false);
|
||||
}
|
||||
catch(
|
||||
boost::exception & x )
|
||||
{
|
||||
boost::shared_ptr<char const * const> file=boost::get_error_info<boost::throw_function>(x);
|
||||
boost::shared_ptr<char const * const> function=boost::get_error_info<boost::throw_file>(x);
|
||||
boost::shared_ptr<int const> line=boost::get_error_info<boost::throw_line>(x);
|
||||
BOOST_TEST( file && *file );
|
||||
BOOST_TEST( function && *function );
|
||||
BOOST_TEST( line && *line==32 );
|
||||
}
|
||||
catch(
|
||||
... )
|
||||
{
|
||||
BOOST_TEST(false);
|
||||
}
|
||||
try
|
||||
{
|
||||
BOOST_THROW_EXCEPTION(exception2() << test_data(42));
|
||||
BOOST_TEST(false);
|
||||
}
|
||||
catch(
|
||||
boost::exception & x )
|
||||
{
|
||||
boost::shared_ptr<char const * const> file=boost::get_error_info<boost::throw_function>(x);
|
||||
boost::shared_ptr<char const * const> function=boost::get_error_info<boost::throw_file>(x);
|
||||
boost::shared_ptr<int const> line=boost::get_error_info<boost::throw_line>(x);
|
||||
boost::shared_ptr<int const> data=boost::get_error_info<test_data>(x);
|
||||
BOOST_TEST( file && *file );
|
||||
BOOST_TEST( function && *function );
|
||||
BOOST_TEST( line && *line==52 );
|
||||
BOOST_TEST( data && *data==42 );
|
||||
}
|
||||
catch(
|
||||
... )
|
||||
{
|
||||
BOOST_TEST(false);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
throw_fwd( void (*thrower)(int) )
|
||||
{
|
||||
@ -46,9 +107,26 @@ tester()
|
||||
catch(
|
||||
T & y )
|
||||
{
|
||||
BOOST_TEST(boost::get_error_info<test_data>(y));
|
||||
if( boost::shared_ptr<int const> d=boost::get_error_info<test_data>(y) )
|
||||
BOOST_TEST(*d==42);
|
||||
#ifdef BOOST_NO_RTTI
|
||||
try
|
||||
{
|
||||
throw;
|
||||
}
|
||||
catch(
|
||||
boost::exception & y )
|
||||
{
|
||||
#endif
|
||||
BOOST_TEST(boost::get_error_info<test_data>(y));
|
||||
if( boost::shared_ptr<int const> d=boost::get_error_info<test_data>(y) )
|
||||
BOOST_TEST(*d==42);
|
||||
#ifdef BOOST_NO_RTTI
|
||||
}
|
||||
catch(
|
||||
... )
|
||||
{
|
||||
BOOST_TEST(false);
|
||||
}
|
||||
#endif
|
||||
BOOST_TEST(y.x_==42);
|
||||
}
|
||||
catch(
|
||||
@ -62,6 +140,7 @@ tester()
|
||||
int
|
||||
main()
|
||||
{
|
||||
boost_throw_exception_test();
|
||||
tester<boost::exception_test::derives_boost_exception>();
|
||||
tester<boost::exception_test::derives_boost_exception_virtually>();
|
||||
tester<boost::exception_test::derives_std_exception>();
|
||||
|
Reference in New Issue
Block a user