• 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 #define BOOST_NORETURN
7 #include <boost/config.hpp>
8 
9 #if !defined( BOOST_NO_EXCEPTIONS )
10 #   error This program requires exception handling disabled.
11 #endif
12 
13 #include <boost/exception_ptr.hpp>
14 #include <boost/exception/get_error_info.hpp>
15 #include <boost/detail/lightweight_test.hpp>
16 
17 typedef boost::error_info<struct tag_answer,int> answer;
18 
19 int exc_count;
20 
21 struct
22 err:
23     virtual boost::exception,
24     virtual std::exception
25     {
errerr26     err()
27         {
28         ++exc_count;
29         }
30 
errerr31     err( err const & )
32         {
33         ++exc_count;
34         }
35 
36     virtual
~errerr37     ~err() BOOST_NOEXCEPT_OR_NOTHROW
38         {
39         --exc_count;
40         }
41 
42     private:
43 
44     err & operator=( err const & );
45     };
46 
47 
48 namespace
49     {
50     bool throw_exception_called;
51     }
52 
53 // It is not valid to return to the caller but we do for testing purposes.
54 namespace
55 boost
56     {
57     void
throw_exception(std::exception const & e)58     throw_exception( std::exception const & e )
59         {
60         throw_exception_called = true;
61         BOOST_TEST(dynamic_cast<err const *>(&e)!=0);
62         int const * ans=boost::get_error_info<answer>(e);
63         BOOST_TEST(ans && *ans==42);
64         }
65 
66     struct source_location;
67     void
throw_exception(std::exception const & e,boost::source_location const &)68     throw_exception( std::exception const & e, boost::source_location const & )
69         {
70         throw_exception_called = true;
71         BOOST_TEST(dynamic_cast<err const *>(&e)!=0);
72         int const * ans=boost::get_error_info<answer>(e);
73         BOOST_TEST(ans && *ans==42);
74         }
75     }
76 
77 void
simple_test()78 simple_test()
79     {
80     boost::exception_ptr p = boost::copy_exception(err() << answer(42));
81     throw_exception_called = false;
82     boost::exception_detail::rethrow_exception_(p);
83     BOOST_TEST(throw_exception_called);
84     }
85 
86 int
main()87 main()
88     {
89     BOOST_TEST(++exc_count==1);
90     simple_test();
91     BOOST_TEST(!--exc_count);
92     return boost::report_errors();
93     }
94