1//// 2Copyright 2019 Peter Dimov 3Distributed under the Boost Software License, Version 1.0. 4http://www.boost.org/LICENSE_1_0.txt 5//// 6 7[#reference] 8# Reference 9:toc: 10:toc-title: 11:idprefix: 12 13[#synopsis] 14## <boost/throw_exception.hpp> Synopsis 15 16``` 17#include <boost/assert/source_location.hpp> 18#include <boost/config.hpp> 19#include <exception> 20 21namespace boost 22{ 23 24#if defined( BOOST_NO_EXCEPTIONS ) 25 26BOOST_NORETURN void throw_exception( std::exception const & e ); // user defined 27 28BOOST_NORETURN void throw_exception( std::exception const & e, 29 boost::source_location const & loc ); // user defined 30 31#else 32 33template<class E> BOOST_NORETURN void throw_exception( E const & e ); 34 35template<class E> BOOST_NORETURN void throw_exception( E const & e, 36 boost::source_location const & loc ); 37 38#endif 39 40} // namespace boost 41 42#define BOOST_THROW_EXCEPTION(x) \ 43 ::boost::throw_exception(x, BOOST_CURRENT_LOCATION) 44``` 45 46## throw_exception 47 48``` 49#if defined( BOOST_NO_EXCEPTIONS ) 50 51BOOST_NORETURN void throw_exception( std::exception const & e ); // user defined 52 53#else 54 55template<class E> BOOST_NORETURN void throw_exception( E const & e ); 56 57#endif 58``` 59 60Requires: :: `E` must have `std::exception` as a public and unambiguous base 61 class. 62 63Effects: :: 64 * When exceptions aren't available, the function is declared, but 65 not defined. The user is expected to supply an appropriate definition. 66 * Otherwise, if `BOOST_EXCEPTION_DISABLE` is defined, the function 67 throws `e`. 68 * Otherwise, the function throws an object of a type derived from `E`, 69 derived from `boost::exception`, if `E` doesn't already derive from 70 it, and containing the necessary support for `boost::exception_ptr`. 71 72``` 73#if defined( BOOST_NO_EXCEPTIONS ) 74 75BOOST_NORETURN void throw_exception( std::exception const & e, 76 boost::source_location const & loc ); // user defined 77 78#else 79 80template<class E> BOOST_NORETURN void throw_exception( E const & e, 81 boost::source_location const & loc ); 82 83#endif 84``` 85 86Requires: :: `E` must have `std::exception` as a public and unambiguous base 87 class. 88 89Effects: :: 90 * When exceptions aren't available, the function is declared, but 91 not defined. The user is expected to supply an appropriate definition. 92 * Otherwise, if `BOOST_EXCEPTION_DISABLE` is defined, the function 93 throws `e`. 94 * Otherwise, the function throws an object of a type derived from `E`, 95 derived from `boost::exception`, if `E` doesn't already derive from 96 it, and containing the necessary support for `boost::exception_ptr`. The 97 `boost::exception` base class is initialized to contain the source 98 location `loc`. 99