1#ifndef BOOST_THROW_EXCEPTION_HPP_INCLUDED
2#define BOOST_THROW_EXCEPTION_HPP_INCLUDED
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//
13// Copyright (c) 2002, 2018, 2019 Peter Dimov
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//
20// http://www.boost.org/libs/throw_exception
21//
22
23#include <boost/assert/source_location.hpp>
24#include <boost/config.hpp>
25#include <boost/config/workaround.hpp>
26#include <exception>
27
28#if !defined( BOOST_EXCEPTION_DISABLE ) && defined( BOOST_BORLANDC ) && BOOST_WORKAROUND( BOOST_BORLANDC, BOOST_TESTED_AT(0x593) )
29# define BOOST_EXCEPTION_DISABLE
30#endif
31
32namespace boost
33{
34
35// All boost exceptions are required to derive from std::exception,
36// to ensure compatibility with BOOST_NO_EXCEPTIONS.
37
38inline void throw_exception_assert_compatibility( std::exception const & ) {}
39
40} // namespace boost
41
42#if defined( BOOST_NO_EXCEPTIONS )
43
44namespace boost
45{
46
47BOOST_NORETURN void throw_exception( std::exception const & e ); // user defined
48BOOST_NORETURN void throw_exception( std::exception const & e, boost::source_location const & loc ); // user defined
49
50} // namespace boost
51
52#elif defined( BOOST_EXCEPTION_DISABLE )
53
54namespace boost
55{
56
57template<class E> BOOST_NORETURN void throw_exception( E const & e )
58{
59 throw_exception_assert_compatibility( e );
60 throw e;
61}
62
63template<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
75namespace boost
76{
77
78// boost::wrapexcept<E>
79
80namespace detail
81{
82
83typedef char (&wrapexcept_s1)[ 1 ];
84typedef char (&wrapexcept_s2)[ 2 ];
85
86template<class T> wrapexcept_s1 wrapexcept_is_convertible( T* );
87template<class T> wrapexcept_s2 wrapexcept_is_convertible( void* );
88
89template<class E, class B, int I = sizeof( wrapexcept_is_convertible<B>( static_cast< E* >( 0 ) ) ) > struct wrapexcept_add_base;
90
91template<class E, class B> struct wrapexcept_add_base<E, B, 1>
92{
93 struct type {};
94};
95
96template<class E, class B> struct wrapexcept_add_base<E, B, 2>
97{
98 typedef B type;
99};
100
101} // namespace detail
102
103template<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{
108private:
109
110 struct deleter
111 {
112 wrapexcept * p_;
113 ~deleter() { delete p_; }
114 };
115
116private:
117
118 void copy_from( void const* )
119 {
120 }
121
122 void copy_from( boost::exception const* p )
123 {
124 static_cast<boost::exception&>( *this ) = *p;
125 }
126
127public:
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
143 virtual boost::exception_detail::clone_base const * clone() const BOOST_OVERRIDE
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
154 virtual void rethrow() const BOOST_OVERRIDE
155 {
156 throw *this;
157 }
158};
159
160// boost::throw_exception
161
162template<class E> BOOST_NORETURN void throw_exception( E const & e )
163{
164 throw_exception_assert_compatibility( e );
165 throw wrapexcept<E>( e );
166}
167
168template<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
174} // namespace boost
175
176#endif
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
183

source code of include/boost/throw_exception.hpp