1 //Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc.
3 //Distributed under the Boost Software License, Version 1.0. (See accompanying
4 //file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 #include <boost/exception/get_error_info.hpp>
8 #include <boost/exception/info.hpp>
9 #include <boost/exception_ptr.hpp>
10 #include <boost/detail/lightweight_test.hpp>
12 typedef boost::error_info
<struct tag_test_int
,int> test_data
;
28 boost_throw_exception_test()
32 BOOST_THROW_EXCEPTION(exception1());
33 BOOST_ERROR("BOOST_THROW_EXCEPTION failed to throw.");
36 boost::exception
& x
)
38 char const * const * function
=boost::get_error_info
<boost::throw_function
>(x
);
39 char const * const * file
=boost::get_error_info
<boost::throw_file
>(x
);
40 int const * line
=boost::get_error_info
<boost::throw_line
>(x
);
41 BOOST_TEST( file
&& *file
);
42 BOOST_TEST( function
&& *function
);
43 BOOST_TEST( line
&& *line
==32 );
52 BOOST_THROW_EXCEPTION(exception2() << test_data(42));
53 BOOST_ERROR("BOOST_THROW_EXCEPTION failed to throw.");
56 boost::exception
& x
)
58 char const * const * function
=boost::get_error_info
<boost::throw_function
>(x
);
59 char const * const * file
=boost::get_error_info
<boost::throw_file
>(x
);
60 int const * line
=boost::get_error_info
<boost::throw_line
>(x
);
61 int const * data
=boost::get_error_info
<test_data
>(x
);
62 BOOST_TEST( file
&& *file
);
63 BOOST_TEST( function
&& *function
);
64 BOOST_TEST( line
&& *line
==52 );
65 BOOST_TEST( data
&& *data
==42 );
75 throw_fwd( void (*thrower
)(int) )
82 boost::exception
& x
)
95 throw_fwd( &boost::exception_test::throw_test_exception
<T
> );
101 boost::exception_ptr p
= boost::current_exception();
104 rethrow_exception(p
);
116 boost::exception
& y
)
119 BOOST_TEST(boost::get_error_info
<test_data
>(y
));
120 if( int const * d
=boost::get_error_info
<test_data
>(y
) )
130 BOOST_TEST(y
.x_
==42);
143 boost_throw_exception_test();
144 tester
<boost::exception_test::derives_boost_exception
>();
145 tester
<boost::exception_test::derives_boost_exception_virtually
>();
146 tester
<boost::exception_test::derives_std_exception
>();
147 return boost::report_errors();