• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 Peter Dimov
2 //
3 // Distributed under the Boost Software License, Version 1.0.
4 //
5 // See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt
7 
8 #if defined(_MSC_VER)
9 # pragma warning(disable: 4702) // unreachable code
10 #endif
11 
12 #if defined(__clang__)
13 # pragma clang diagnostic ignored "-Wunknown-pragmas"
14 # pragma clang diagnostic ignored "-Wunknown-warning-option"
15 # pragma clang diagnostic ignored "-Wpotentially-evaluated-expression"
16 # pragma clang diagnostic ignored "-Wdelete-non-abstract-non-virtual-dtor"
17 # pragma clang diagnostic ignored "-Wunused-parameter"
18 #endif
19 
20 #include "lib1_throw.hpp"
21 #include "lib2_throw.hpp"
22 #include "lib3_throw.hpp"
23 #include <boost/exception/exception.hpp>
24 #include <boost/exception_ptr.hpp>
25 #include <boost/exception/get_error_info.hpp>
26 #include <boost/core/lightweight_test.hpp>
27 
test_catch_by_type()28 void test_catch_by_type()
29 {
30     BOOST_TEST_THROWS( lib1::f(), lib1::exception );
31     BOOST_TEST_THROWS( lib2::f(), lib2::exception );
32     BOOST_TEST_THROWS( lib3::f(), lib3::exception );
33 }
34 
test_catch_by_exception()35 void test_catch_by_exception()
36 {
37     BOOST_TEST_THROWS( lib2::f(), boost::exception );
38     BOOST_TEST_THROWS( lib3::f(), boost::exception );
39 }
40 
test_exception_ptr()41 void test_exception_ptr()
42 {
43     try
44     {
45         lib2::f();
46     }
47     catch( ... )
48     {
49         boost::exception_ptr p = boost::current_exception();
50 
51         BOOST_TEST_THROWS( boost::rethrow_exception( p ), lib2::exception );
52         BOOST_TEST_THROWS( boost::rethrow_exception( p ), boost::exception );
53     }
54 
55     try
56     {
57         lib3::f();
58     }
59     catch( ... )
60     {
61         boost::exception_ptr p = boost::current_exception();
62 
63         BOOST_TEST_THROWS( boost::rethrow_exception( p ), lib3::exception );
64         BOOST_TEST_THROWS( boost::rethrow_exception( p ), boost::exception );
65     }
66 }
67 
test_throw_line()68 void test_throw_line()
69 {
70     try
71     {
72         lib3::f();
73     }
74     catch( boost::exception const & x )
75     {
76         int const * line = boost::get_error_info<boost::throw_line>( x );
77 
78         BOOST_TEST( line != 0 );
79         BOOST_TEST_EQ( *line, 13 );
80     }
81 }
82 
main()83 int main()
84 {
85     test_catch_by_type();
86     test_catch_by_exception();
87     test_exception_ptr();
88     test_throw_line();
89 
90     return boost::report_errors();
91 }
92