#ifndef _LIBCPP_EXCEPTION
#define _LIBCPP_EXCEPTION
#include <__config>
#include <cstddef>
#include <type_traits>
#pragma GCC system_header
namespace std {
class _LIBCPP_EXCEPTION_ABI exception
{
public:
_LIBCPP_INLINE_VISIBILITY exception() throw() {}
virtual ~exception() throw();
virtual const char* what() const throw();
};
class _LIBCPP_EXCEPTION_ABI bad_exception
: public exception
{
public:
_LIBCPP_INLINE_VISIBILITY bad_exception() throw() {}
virtual ~bad_exception() throw();
virtual const char* what() const throw();
};
typedef void (*unexpected_handler)();
_LIBCPP_VISIBLE unexpected_handler set_unexpected(unexpected_handler) throw();
_LIBCPP_VISIBLE unexpected_handler get_unexpected() throw();
_LIBCPP_VISIBLE void unexpected();
typedef void (*terminate_handler)();
_LIBCPP_VISIBLE terminate_handler set_terminate(terminate_handler) throw();
_LIBCPP_VISIBLE terminate_handler get_terminate() throw();
_LIBCPP_VISIBLE void terminate() __attribute__((__noreturn__));
_LIBCPP_VISIBLE bool uncaught_exception() throw();
class exception_ptr;
exception_ptr current_exception();
void rethrow_exception(exception_ptr);
class _LIBCPP_VISIBLE exception_ptr
{
void* __ptr_;
public:
_LIBCPP_INLINE_VISIBILITY exception_ptr() : __ptr_() {}
_LIBCPP_INLINE_VISIBILITY exception_ptr(nullptr_t) : __ptr_() {}
exception_ptr(const exception_ptr&);
exception_ptr& operator=(const exception_ptr&);
~exception_ptr();
_LIBCPP_INLINE_VISIBILITY
operator bool() const {return __ptr_ != nullptr;}
friend _LIBCPP_INLINE_VISIBILITY
bool operator==(const exception_ptr& __x, const exception_ptr& __y)
{return __x.__ptr_ == __y.__ptr_;}
friend _LIBCPP_INLINE_VISIBILITY
bool operator!=(const exception_ptr& __x, const exception_ptr& __y)
{return !(__x == __y);}
friend exception_ptr current_exception();
friend void rethrow_exception(exception_ptr); };
template<class _E>
exception_ptr
make_exception_ptr(_E __e)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
throw __e;
}
catch (...)
{
return current_exception();
}
#endif // _LIBCPP_NO_EXCEPTIONS
}
class _LIBCPP_EXCEPTION_ABI nested_exception
{
exception_ptr __ptr_;
public:
nested_exception();
virtual ~nested_exception();
void rethrow_nested () const;
_LIBCPP_INLINE_VISIBILITY exception_ptr nested_ptr() const {return __ptr_;}
};
template <class _Tp>
struct __nested
: public _Tp,
public nested_exception
{
_LIBCPP_INLINE_VISIBILITY explicit __nested(const _Tp& __t) : _Tp(__t) {}
};
template <class _Tp>
void
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
throw_with_nested (_Tp&& __t, typename enable_if<
is_class<typename remove_reference<_Tp>::type>::value &&
!is_base_of<nested_exception, typename remove_reference<_Tp>::type>::value
>::type* = 0)
#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
throw_with_nested (_Tp& __t, typename enable_if<
is_class<_Tp>::value && !is_base_of<nested_exception, _Tp>::value
>::type* = 0)
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
{
#ifndef _LIBCPP_NO_EXCEPTIONS
throw __nested<typename remove_reference<_Tp>::type>(_STD::forward<_Tp>(__t));
#endif
}
template <class _Tp>
void
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
throw_with_nested (_Tp&& __t, typename enable_if<
!is_class<typename remove_reference<_Tp>::type>::value ||
is_base_of<nested_exception, typename remove_reference<_Tp>::type>::value
>::type* = 0)
#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
throw_with_nested (_Tp& __t, typename enable_if<
!is_class<_Tp>::value || is_base_of<nested_exception, _Tp>::value
>::type* = 0)
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
{
#ifndef _LIBCPP_NO_EXCEPTIONS
throw _STD::forward<_Tp>(__t);
#endif
}
template <class _E>
inline _LIBCPP_INLINE_VISIBILITY
void
rethrow_if_nested(const _E& __e, typename enable_if<
is_polymorphic<_E>::value
>::type* = 0)
{
const nested_exception* __nep = dynamic_cast<const nested_exception*>(&__e);
if (__nep)
__nep->rethrow_nested();
}
template <class _E>
inline _LIBCPP_INLINE_VISIBILITY
void
rethrow_if_nested(const _E& __e, typename enable_if<
!is_polymorphic<_E>::value
>::type* = 0)
{
}
}
#endif // _LIBCPP_EXCEPTION