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 #define BOOST_NO_EXCEPTIONS 7 #include <boost/config.hpp> 8 #include <boost/throw_exception.hpp> 9 #include <boost/exception/info.hpp> 10 #include <boost/exception/diagnostic_information.hpp> 11 #include <boost/core/lightweight_test.hpp> 12 #include <stdlib.h> 13 14 struct 15 my_exception: 16 boost::exception, 17 std::exception 18 { 19 char const * whatmy_exception20 what() const BOOST_NOEXCEPT_OR_NOTHROW 21 { 22 return "my_exception"; 23 } 24 }; 25 26 typedef boost::error_info<struct my_tag,int> my_int; 27 28 bool called=false; 29 30 namespace 31 boost 32 { 33 void throw_exception(std::exception const & x)34 throw_exception( std::exception const & x ) 35 { 36 called=true; 37 std::string s=boost::diagnostic_information(x); 38 std::cout << s; 39 #ifndef BOOST_NO_RTTI 40 BOOST_TEST(s.find("my_tag")!=std::string::npos); 41 #endif 42 exit(boost::report_errors()); 43 } 44 void throw_exception(std::exception const & x,boost::source_location const &)45 throw_exception(std::exception const & x, boost::source_location const &) 46 { 47 throw_exception(x); 48 } 49 } 50 51 int main()52main() 53 { 54 BOOST_THROW_EXCEPTION( my_exception() << my_int(42) ); 55 BOOST_TEST(called); 56 return boost::report_errors(); 57 } 58