]>
Commit | Line | Data |
---|---|---|
f67539c2 TL |
1 | #ifndef BOOST_THROW_EXCEPTION_HPP_INCLUDED |
2 | #define BOOST_THROW_EXCEPTION_HPP_INCLUDED | |
7c673cae FG |
3 | |
4 | // MS compatible compilers support #pragma once | |
5 | ||
6 | #if defined(_MSC_VER) && (_MSC_VER >= 1020) | |
7 | # pragma once | |
8 | #endif | |
9 | ||
10 | // | |
11 | // boost/throw_exception.hpp | |
12 | // | |
f67539c2 | 13 | // Copyright (c) 2002, 2018, 2019 Peter Dimov |
7c673cae FG |
14 | // Copyright (c) 2008-2009 Emil Dotchevski and Reverge Studios, Inc. |
15 | // | |
16 | // Distributed under the Boost Software License, Version 1.0. (See | |
17 | // accompanying file LICENSE_1_0.txt or copy at | |
18 | // http://www.boost.org/LICENSE_1_0.txt) | |
19 | // | |
f67539c2 | 20 | // http://www.boost.org/libs/throw_exception |
7c673cae FG |
21 | // |
22 | ||
f67539c2 | 23 | #include <boost/assert/source_location.hpp> |
7c673cae | 24 | #include <boost/config.hpp> |
f67539c2 | 25 | #include <boost/config/workaround.hpp> |
7c673cae FG |
26 | #include <exception> |
27 | ||
20effc67 | 28 | #if !defined( BOOST_EXCEPTION_DISABLE ) && defined( BOOST_BORLANDC ) && BOOST_WORKAROUND( BOOST_BORLANDC, BOOST_TESTED_AT(0x593) ) |
7c673cae FG |
29 | # define BOOST_EXCEPTION_DISABLE |
30 | #endif | |
31 | ||
f67539c2 TL |
32 | namespace boost |
33 | { | |
7c673cae | 34 | |
f67539c2 TL |
35 | // All boost exceptions are required to derive from std::exception, |
36 | // to ensure compatibility with BOOST_NO_EXCEPTIONS. | |
7c673cae | 37 | |
f67539c2 TL |
38 | inline void throw_exception_assert_compatibility( std::exception const & ) {} |
39 | ||
40 | } // namespace boost | |
41 | ||
42 | #if defined( BOOST_NO_EXCEPTIONS ) | |
92f5a8d4 | 43 | |
7c673cae FG |
44 | namespace boost |
45 | { | |
7c673cae | 46 | |
92f5a8d4 | 47 | BOOST_NORETURN void throw_exception( std::exception const & e ); // user defined |
f67539c2 | 48 | BOOST_NORETURN void throw_exception( std::exception const & e, boost::source_location const & loc ); // user defined |
7c673cae | 49 | |
f67539c2 | 50 | } // namespace boost |
7c673cae | 51 | |
f67539c2 | 52 | #elif defined( BOOST_EXCEPTION_DISABLE ) |
7c673cae | 53 | |
f67539c2 | 54 | namespace boost |
7c673cae | 55 | { |
7c673cae | 56 | |
f67539c2 TL |
57 | template<class E> BOOST_NORETURN void throw_exception( E const & e ) |
58 | { | |
59 | throw_exception_assert_compatibility( e ); | |
7c673cae | 60 | throw e; |
7c673cae FG |
61 | } |
62 | ||
f67539c2 TL |
63 | template<class E> BOOST_NORETURN void throw_exception( E const & e, boost::source_location const & ) |
64 | { | |
65 | throw_exception_assert_compatibility( e ); | |
66 | throw e; | |
67 | } | |
68 | ||
69 | } // namespace boost | |
70 | ||
71 | #else // !defined( BOOST_NO_EXCEPTIONS ) && !defined( BOOST_EXCEPTION_DISABLE ) | |
72 | ||
73 | #include <boost/exception/exception.hpp> | |
74 | ||
75 | namespace boost | |
76 | { | |
77 | ||
78 | // boost::wrapexcept<E> | |
79 | ||
80 | namespace detail | |
81 | { | |
82 | ||
83 | typedef char (&wrapexcept_s1)[ 1 ]; | |
84 | typedef char (&wrapexcept_s2)[ 2 ]; | |
85 | ||
86 | template<class T> wrapexcept_s1 wrapexcept_is_convertible( T* ); | |
87 | template<class T> wrapexcept_s2 wrapexcept_is_convertible( void* ); | |
88 | ||
89 | template<class E, class B, int I = sizeof( wrapexcept_is_convertible<B>( static_cast< E* >( 0 ) ) ) > struct wrapexcept_add_base; | |
90 | ||
91 | template<class E, class B> struct wrapexcept_add_base<E, B, 1> | |
92 | { | |
93 | struct type {}; | |
94 | }; | |
95 | ||
96 | template<class E, class B> struct wrapexcept_add_base<E, B, 2> | |
97 | { | |
98 | typedef B type; | |
99 | }; | |
100 | ||
101 | } // namespace detail | |
7c673cae | 102 | |
f67539c2 TL |
103 | template<class E> struct BOOST_SYMBOL_VISIBLE wrapexcept: |
104 | public detail::wrapexcept_add_base<E, boost::exception_detail::clone_base>::type, | |
105 | public E, | |
106 | public detail::wrapexcept_add_base<E, boost::exception>::type | |
107 | { | |
108 | private: | |
109 | ||
110 | struct deleter | |
111 | { | |
112 | wrapexcept * p_; | |
113 | ~deleter() { delete p_; } | |
114 | }; | |
115 | ||
116 | private: | |
117 | ||
118 | void copy_from( void const* ) | |
7c673cae | 119 | { |
7c673cae | 120 | } |
f67539c2 TL |
121 | |
122 | void copy_from( boost::exception const* p ) | |
123 | { | |
124 | static_cast<boost::exception&>( *this ) = *p; | |
125 | } | |
126 | ||
127 | public: | |
128 | ||
129 | explicit wrapexcept( E const & e ): E( e ) | |
130 | { | |
131 | copy_from( &e ); | |
132 | } | |
133 | ||
134 | explicit wrapexcept( E const & e, boost::source_location const & loc ): E( e ) | |
135 | { | |
136 | copy_from( &e ); | |
137 | ||
138 | set_info( *this, throw_file( loc.file_name() ) ); | |
139 | set_info( *this, throw_line( loc.line() ) ); | |
140 | set_info( *this, throw_function( loc.function_name() ) ); | |
141 | } | |
142 | ||
20effc67 | 143 | virtual boost::exception_detail::clone_base const * clone() const BOOST_OVERRIDE |
f67539c2 TL |
144 | { |
145 | wrapexcept * p = new wrapexcept( *this ); | |
146 | deleter del = { p }; | |
147 | ||
148 | boost::exception_detail::copy_boost_exception( p, this ); | |
149 | ||
150 | del.p_ = 0; | |
151 | return p; | |
152 | } | |
153 | ||
20effc67 | 154 | virtual void rethrow() const BOOST_OVERRIDE |
f67539c2 TL |
155 | { |
156 | throw *this; | |
157 | } | |
158 | }; | |
159 | ||
160 | // boost::throw_exception | |
161 | ||
162 | template<class E> BOOST_NORETURN void throw_exception( E const & e ) | |
163 | { | |
164 | throw_exception_assert_compatibility( e ); | |
165 | throw wrapexcept<E>( e ); | |
166 | } | |
167 | ||
168 | template<class E> BOOST_NORETURN void throw_exception( E const & e, boost::source_location const & loc ) | |
169 | { | |
170 | throw_exception_assert_compatibility( e ); | |
171 | throw wrapexcept<E>( e, loc ); | |
172 | } | |
173 | ||
7c673cae FG |
174 | } // namespace boost |
175 | ||
7c673cae | 176 | #endif |
f67539c2 TL |
177 | |
178 | // BOOST_THROW_EXCEPTION | |
179 | ||
180 | #define BOOST_THROW_EXCEPTION(x) ::boost::throw_exception(x, BOOST_CURRENT_LOCATION) | |
181 | ||
182 | #endif // #ifndef BOOST_THROW_EXCEPTION_HPP_INCLUDED |