| 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 | |
| 32 | namespace boost |
| 33 | { |
| 34 | |
| 35 | // All boost exceptions are required to derive from std::exception, |
| 36 | // to ensure compatibility with BOOST_NO_EXCEPTIONS. |
| 37 | |
| 38 | inline void throw_exception_assert_compatibility( std::exception const & ) {} |
| 39 | |
| 40 | } // namespace boost |
| 41 | |
| 42 | #if defined( BOOST_NO_EXCEPTIONS ) |
| 43 | |
| 44 | namespace boost |
| 45 | { |
| 46 | |
| 47 | BOOST_NORETURN void throw_exception( std::exception const & e ); // user defined |
| 48 | BOOST_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 | |
| 54 | namespace boost |
| 55 | { |
| 56 | |
| 57 | template<class E> BOOST_NORETURN void throw_exception( E const & e ) |
| 58 | { |
| 59 | throw_exception_assert_compatibility( e ); |
| 60 | throw e; |
| 61 | } |
| 62 | |
| 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 |
| 102 | |
| 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* ) |
| 119 | { |
| 120 | } |
| 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 | |
| 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 | |
| 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 | |
| 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 | |