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