1 #ifndef BOOST_THROW_EXCEPTION_HPP_INCLUDED
2 #define BOOST_THROW_EXCEPTION_HPP_INCLUDED
4 // MS compatible compilers support #pragma once
6 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
11 // boost/throw_exception.hpp
13 // Copyright (c) 2002, 2018, 2019 Peter Dimov
14 // Copyright (c) 2008-2009 Emil Dotchevski and Reverge Studios, Inc.
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)
20 // http://www.boost.org/libs/throw_exception
23 #include <boost/assert/source_location.hpp>
24 #include <boost/config.hpp>
25 #include <boost/config/workaround.hpp>
28 #if !defined( BOOST_EXCEPTION_DISABLE ) && defined( BOOST_BORLANDC ) && BOOST_WORKAROUND( BOOST_BORLANDC, BOOST_TESTED_AT(0x593) )
29 # define BOOST_EXCEPTION_DISABLE
35 // All boost exceptions are required to derive from std::exception,
36 // to ensure compatibility with BOOST_NO_EXCEPTIONS.
38 inline void throw_exception_assert_compatibility( std::exception const & ) {}
42 #if defined( BOOST_NO_EXCEPTIONS )
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
52 #elif defined( BOOST_EXCEPTION_DISABLE )
57 template<class E> BOOST_NORETURN void throw_exception( E const & e )
59 throw_exception_assert_compatibility( e );
63 template<class E> BOOST_NORETURN void throw_exception( E const & e, boost::source_location const & )
65 throw_exception_assert_compatibility( e );
71 #else // !defined( BOOST_NO_EXCEPTIONS ) && !defined( BOOST_EXCEPTION_DISABLE )
73 #include <boost/exception/exception.hpp>
78 // boost::wrapexcept<E>
83 typedef char (&wrapexcept_s1)[ 1 ];
84 typedef char (&wrapexcept_s2)[ 2 ];
86 template<class T> wrapexcept_s1 wrapexcept_is_convertible( T* );
87 template<class T> wrapexcept_s2 wrapexcept_is_convertible( void* );
89 template<class E, class B, int I = sizeof( wrapexcept_is_convertible<B>( static_cast< E* >( 0 ) ) ) > struct wrapexcept_add_base;
91 template<class E, class B> struct wrapexcept_add_base<E, B, 1>
96 template<class E, class B> struct wrapexcept_add_base<E, B, 2>
101 } // namespace detail
103 template<class E> struct BOOST_SYMBOL_VISIBLE wrapexcept:
104 public detail::wrapexcept_add_base<E, boost::exception_detail::clone_base>::type,
106 public detail::wrapexcept_add_base<E, boost::exception>::type
113 ~deleter() { delete p_; }
118 void copy_from( void const* )
122 void copy_from( boost::exception const* p )
124 static_cast<boost::exception&>( *this ) = *p;
129 explicit wrapexcept( E const & e ): E( e )
134 explicit wrapexcept( E const & e, boost::source_location const & loc ): E( e )
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() ) );
143 virtual boost::exception_detail::clone_base const * clone() const BOOST_OVERRIDE
145 wrapexcept * p = new wrapexcept( *this );
148 boost::exception_detail::copy_boost_exception( p, this );
154 virtual void rethrow() const BOOST_OVERRIDE
160 // boost::throw_exception
162 template<class E> BOOST_NORETURN void throw_exception( E const & e )
164 throw_exception_assert_compatibility( e );
165 throw wrapexcept<E>( e );
168 template<class E> BOOST_NORETURN void throw_exception( E const & e, boost::source_location const & loc )
170 throw_exception_assert_compatibility( e );
171 throw wrapexcept<E>( e, loc );
178 // BOOST_THROW_EXCEPTION
180 #define BOOST_THROW_EXCEPTION(x) ::boost::throw_exception(x, BOOST_CURRENT_LOCATION)
182 #endif // #ifndef BOOST_THROW_EXCEPTION_HPP_INCLUDED