3.8 KiB
Reference
<boost/throw_exception.hpp> Synopsis
#include <boost/assert/source_location.hpp>
#include <boost/config.hpp>
#include <exception>
namespace boost
{
#if defined( BOOST_NO_EXCEPTIONS )
BOOST_NORETURN void throw_exception( std::exception const & e ); // user defined
BOOST_NORETURN void throw_exception( std::exception const & e,
boost::source_location const & loc ); // user defined
#else
template<class E> BOOST_NORETURN void throw_exception( E const & e );
template<class E> BOOST_NORETURN void throw_exception( E const & e,
boost::source_location const & loc );
#endif
} // namespace boost
#define BOOST_THROW_EXCEPTION(x) \
::boost::throw_exception(x, BOOST_CURRENT_LOCATION)
namespace boost
{
template<class E> BOOST_NORETURN void throw_with_location( E && e,
boost::source_location const & loc = BOOST_CURRENT_LOCATION );
template<class E> boost::source_location get_throw_location( E const & e );
} // namespace boost
throw_exception
#if defined( BOOST_NO_EXCEPTIONS )
BOOST_NORETURN void throw_exception( std::exception const & e ); // user defined
#else
template<class E> BOOST_NORETURN void throw_exception( E const & e );
#endif
- Requires:
-
Emust havestd::exceptionas a public and unambiguous base class. - Effects:
-
-
When exceptions aren’t available, the function is declared, but not defined. The user is expected to supply an appropriate definition.
-
Otherwise, if
BOOST_EXCEPTION_DISABLEis defined, the function throwse. -
Otherwise, the function throws an object of a type derived from
E, derived fromboost::exception, ifEdoesn’t already derive from it, and containing the necessary support forboost::exception_ptr.
-
#if defined( BOOST_NO_EXCEPTIONS )
BOOST_NORETURN void throw_exception( std::exception const & e,
boost::source_location const & loc ); // user defined
#else
template<class E> BOOST_NORETURN void throw_exception( E const & e,
boost::source_location const & loc );
#endif
- Requires:
-
Emust havestd::exceptionas a public and unambiguous base class. - Effects:
-
-
When exceptions aren’t available, the function is declared, but not defined. The user is expected to supply an appropriate definition.
-
Otherwise, if
BOOST_EXCEPTION_DISABLEis defined, the function throwse. -
Otherwise, the function throws an object of a type derived from
E, derived fromboost::exception, ifEdoesn’t already derive from it, and containing the necessary support forboost::exception_ptr. Theboost::exceptionbase class is initialized to contain the source locationloc.
-
throw_with_location
template<class E> BOOST_NORETURN void throw_with_location( E && e,
boost::source_location const & loc = BOOST_CURRENT_LOCATION );
- Requires:
-
std::decay<E>::typemust havestd::exceptionas a public and unambiguous base class. - Effects:
-
-
When exceptions aren’t available,
boost::throw_exception( e, loc ); -
Otherwise, the function throws an object of a type derived from
E, such that, if this objectxis caught asstd::exceptionorE,boost::get_throw_location( x )would returnloc.
-
get_throw_location
template<class E> boost::source_location get_throw_location( E const & e );
- Requires:
-
Emust be polymorphic. - Effects:
-
-
If
eis a subobject of the object thrown byboost::throw_with_location( x, loc ), returnsloc. -
If
dynamic_cast<boost::exception const*>( e )returns a nonzero value, returns the source location stored in thatboost::exceptionsubobject, if any. -
Otherwise, returns a default constructed source location.
-