1 //Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc. 2 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) 5 6 #include "helper1.hpp" 7 #include <boost/exception/get_error_info.hpp> 8 #include <boost/exception/info.hpp> 9 #include <boost/exception/diagnostic_information.hpp> 10 #include <boost/detail/lightweight_test.hpp> 11 12 namespace 13 { 14 typedef boost::error_info<struct tag_test_int,int> test_int; 15 16 void throw_wrapper()17 throw_wrapper() 18 { 19 try 20 { 21 boost::exception_test::throw_length_error(); 22 } 23 catch( 24 boost::exception & x ) 25 { 26 x << test_int(42); 27 throw; 28 } 29 catch( 30 ... ) 31 { 32 BOOST_TEST(false); 33 } 34 } 35 } 36 37 int main()38main() 39 { 40 try 41 { 42 throw_wrapper(); 43 BOOST_TEST(false); 44 } 45 catch( 46 std::exception & x ) 47 { 48 #ifdef BOOST_NO_RTTI 49 try 50 { 51 throw; 52 } 53 catch( 54 boost::exception & x ) 55 { 56 #endif 57 BOOST_TEST( boost::get_error_info<test_int>(x) ); 58 if( int const * p=boost::get_error_info<test_int>(x) ) 59 BOOST_TEST( 42==*p ); 60 #ifdef BOOST_NO_RTTI 61 } 62 catch( 63 ... ) 64 { 65 BOOST_TEST(false); 66 } 67 #endif 68 BOOST_TEST( std::string(x.what())==std::string("exception test length error") ); 69 } 70 catch( 71 ... ) 72 { 73 BOOST_TEST(false); 74 } 75 return boost::report_errors(); 76 } 77