2010-05-11 21:42:16 +02:00
|
|
|
// -*- C++ -*-
|
|
|
|
//===-------------------------- exception ---------------------------------===//
|
|
|
|
//
|
2010-05-11 23:36:01 +02:00
|
|
|
// The LLVM Compiler Infrastructure
|
2010-05-11 21:42:16 +02:00
|
|
|
//
|
2010-11-16 23:09:02 +01:00
|
|
|
// This file is dual licensed under the MIT and the University of Illinois Open
|
|
|
|
// Source Licenses. See LICENSE.TXT for details.
|
2010-05-11 21:42:16 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef _LIBCPP_EXCEPTION
|
|
|
|
#define _LIBCPP_EXCEPTION
|
|
|
|
|
|
|
|
/*
|
|
|
|
exception synopsis
|
|
|
|
|
|
|
|
namespace std
|
|
|
|
{
|
|
|
|
|
|
|
|
class exception
|
|
|
|
{
|
|
|
|
public:
|
2011-05-26 20:23:59 +02:00
|
|
|
exception() noexcept;
|
|
|
|
exception(const exception&) noexcept;
|
|
|
|
exception& operator=(const exception&) noexcept;
|
|
|
|
virtual ~exception() noexcept;
|
|
|
|
virtual const char* what() const noexcept;
|
2010-05-11 21:42:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class bad_exception
|
|
|
|
: public exception
|
|
|
|
{
|
|
|
|
public:
|
2011-05-26 20:23:59 +02:00
|
|
|
bad_exception() noexcept;
|
|
|
|
bad_exception(const bad_exception&) noexcept;
|
|
|
|
bad_exception& operator=(const bad_exception&) noexcept;
|
|
|
|
virtual ~bad_exception() noexcept;
|
|
|
|
virtual const char* what() const noexcept;
|
2010-05-11 21:42:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef void (*unexpected_handler)();
|
2011-05-26 20:23:59 +02:00
|
|
|
unexpected_handler set_unexpected(unexpected_handler f ) noexcept;
|
|
|
|
unexpected_handler get_unexpected() noexcept;
|
|
|
|
[[noreturn]] void unexpected();
|
2010-05-11 21:42:16 +02:00
|
|
|
|
|
|
|
typedef void (*terminate_handler)();
|
2011-05-26 20:23:59 +02:00
|
|
|
terminate_handler set_terminate(terminate_handler f ) noexcept;
|
|
|
|
terminate_handler get_terminate() noexcept;
|
|
|
|
[[noreturn]] void terminate() noexcept;
|
2010-05-11 21:42:16 +02:00
|
|
|
|
2011-05-26 20:23:59 +02:00
|
|
|
bool uncaught_exception() noexcept;
|
2010-05-11 21:42:16 +02:00
|
|
|
|
|
|
|
typedef unspecified exception_ptr;
|
|
|
|
|
2011-05-26 20:23:59 +02:00
|
|
|
exception_ptr current_exception() noexcept;
|
2010-05-11 21:42:16 +02:00
|
|
|
void rethrow_exception [[noreturn]] (exception_ptr p);
|
2011-05-26 20:23:59 +02:00
|
|
|
template<class E> exception_ptr make_exception_ptr(E e) noexcept;
|
2010-05-11 21:42:16 +02:00
|
|
|
|
|
|
|
class nested_exception
|
|
|
|
{
|
|
|
|
public:
|
2011-05-26 20:23:59 +02:00
|
|
|
nested_exception() noexcept;
|
|
|
|
nested_exception(const nested_exception&) noexcept = default;
|
|
|
|
nested_exception& operator=(const nested_exception&) noexcept = default;
|
2010-05-11 21:42:16 +02:00
|
|
|
virtual ~nested_exception() = default;
|
|
|
|
|
|
|
|
// access functions
|
2011-05-26 20:23:59 +02:00
|
|
|
[[noreturn]] void rethrow_nested() const;
|
|
|
|
exception_ptr nested_ptr() const noexcept;
|
2010-05-11 21:42:16 +02:00
|
|
|
};
|
|
|
|
|
2011-05-26 20:23:59 +02:00
|
|
|
template <class T> [[noreturn]] void throw_with_nested(T&& t);
|
2010-05-11 21:42:16 +02:00
|
|
|
template <class E> void rethrow_if_nested(const E& e);
|
|
|
|
|
|
|
|
} // std
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <__config>
|
|
|
|
#include <cstddef>
|
2010-05-27 19:06:52 +02:00
|
|
|
#include <type_traits>
|
2010-05-11 21:42:16 +02:00
|
|
|
|
2011-10-17 22:05:10 +02:00
|
|
|
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
2010-05-11 21:42:16 +02:00
|
|
|
#pragma GCC system_header
|
2011-10-17 22:05:10 +02:00
|
|
|
#endif
|
2010-05-11 21:42:16 +02:00
|
|
|
|
|
|
|
namespace std // purposefully not using versioning namespace
|
|
|
|
{
|
|
|
|
|
|
|
|
class _LIBCPP_EXCEPTION_ABI exception
|
|
|
|
{
|
|
|
|
public:
|
2011-05-26 20:23:59 +02:00
|
|
|
_LIBCPP_INLINE_VISIBILITY exception() _NOEXCEPT {}
|
|
|
|
virtual ~exception() _NOEXCEPT;
|
|
|
|
virtual const char* what() const _NOEXCEPT;
|
2010-05-11 21:42:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class _LIBCPP_EXCEPTION_ABI bad_exception
|
|
|
|
: public exception
|
|
|
|
{
|
|
|
|
public:
|
2011-05-26 20:23:59 +02:00
|
|
|
_LIBCPP_INLINE_VISIBILITY bad_exception() _NOEXCEPT {}
|
|
|
|
virtual ~bad_exception() _NOEXCEPT;
|
|
|
|
virtual const char* what() const _NOEXCEPT;
|
2010-05-11 21:42:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef void (*unexpected_handler)();
|
2011-05-26 20:23:59 +02:00
|
|
|
_LIBCPP_VISIBLE unexpected_handler set_unexpected(unexpected_handler) _NOEXCEPT;
|
|
|
|
_LIBCPP_VISIBLE unexpected_handler get_unexpected() _NOEXCEPT;
|
2011-05-26 19:07:32 +02:00
|
|
|
_ATTRIBUTE(noreturn) _LIBCPP_VISIBLE void unexpected();
|
2010-05-11 21:42:16 +02:00
|
|
|
|
|
|
|
typedef void (*terminate_handler)();
|
2011-05-26 20:23:59 +02:00
|
|
|
_LIBCPP_VISIBLE terminate_handler set_terminate(terminate_handler) _NOEXCEPT;
|
|
|
|
_LIBCPP_VISIBLE terminate_handler get_terminate() _NOEXCEPT;
|
2011-05-26 19:07:32 +02:00
|
|
|
_ATTRIBUTE(noreturn) _LIBCPP_VISIBLE void terminate() _NOEXCEPT;
|
2010-05-11 21:42:16 +02:00
|
|
|
|
2011-05-26 20:23:59 +02:00
|
|
|
_LIBCPP_VISIBLE bool uncaught_exception() _NOEXCEPT;
|
2010-05-11 21:42:16 +02:00
|
|
|
|
|
|
|
class exception_ptr;
|
|
|
|
|
2011-05-26 20:23:59 +02:00
|
|
|
exception_ptr current_exception() _NOEXCEPT;
|
2011-05-26 19:07:32 +02:00
|
|
|
_ATTRIBUTE(noreturn) void rethrow_exception(exception_ptr);
|
2010-05-11 21:42:16 +02:00
|
|
|
|
2010-09-21 23:28:23 +02:00
|
|
|
class _LIBCPP_VISIBLE exception_ptr
|
2010-05-11 21:42:16 +02:00
|
|
|
{
|
|
|
|
void* __ptr_;
|
|
|
|
public:
|
2011-05-26 20:23:59 +02:00
|
|
|
_LIBCPP_INLINE_VISIBILITY exception_ptr() _NOEXCEPT : __ptr_() {}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY exception_ptr(nullptr_t) _NOEXCEPT : __ptr_() {}
|
|
|
|
exception_ptr(const exception_ptr&) _NOEXCEPT;
|
|
|
|
exception_ptr& operator=(const exception_ptr&) _NOEXCEPT;
|
|
|
|
~exception_ptr() _NOEXCEPT;
|
2010-05-11 21:42:16 +02:00
|
|
|
|
2010-09-21 23:28:23 +02:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2010-05-11 21:42:16 +02:00
|
|
|
// explicit
|
2011-05-26 20:23:59 +02:00
|
|
|
operator bool() const _NOEXCEPT {return __ptr_ != nullptr;}
|
2010-05-11 21:42:16 +02:00
|
|
|
|
2010-09-21 23:28:23 +02:00
|
|
|
friend _LIBCPP_INLINE_VISIBILITY
|
2011-05-26 20:23:59 +02:00
|
|
|
bool operator==(const exception_ptr& __x, const exception_ptr& __y) _NOEXCEPT
|
2010-05-11 21:42:16 +02:00
|
|
|
{return __x.__ptr_ == __y.__ptr_;}
|
2010-09-21 23:28:23 +02:00
|
|
|
friend _LIBCPP_INLINE_VISIBILITY
|
2011-05-26 20:23:59 +02:00
|
|
|
bool operator!=(const exception_ptr& __x, const exception_ptr& __y) _NOEXCEPT
|
2010-05-11 21:42:16 +02:00
|
|
|
{return !(__x == __y);}
|
|
|
|
|
2011-05-26 20:23:59 +02:00
|
|
|
friend exception_ptr current_exception() _NOEXCEPT;
|
2011-05-26 19:07:32 +02:00
|
|
|
_ATTRIBUTE(noreturn) friend void rethrow_exception(exception_ptr);
|
2010-05-11 21:42:16 +02:00
|
|
|
};
|
|
|
|
|
2011-11-29 19:15:50 +01:00
|
|
|
template<class _Ep>
|
2010-05-11 21:42:16 +02:00
|
|
|
exception_ptr
|
2011-11-29 19:15:50 +01:00
|
|
|
make_exception_ptr(_Ep __e) _NOEXCEPT
|
2010-05-11 21:42:16 +02:00
|
|
|
{
|
2010-08-11 19:04:31 +02:00
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
2010-05-11 21:42:16 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
throw __e;
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
return current_exception();
|
|
|
|
}
|
2010-08-22 02:02:43 +02:00
|
|
|
#endif // _LIBCPP_NO_EXCEPTIONS
|
2010-05-11 21:42:16 +02:00
|
|
|
}
|
|
|
|
|
2010-05-27 19:06:52 +02:00
|
|
|
// nested_exception
|
|
|
|
|
|
|
|
class _LIBCPP_EXCEPTION_ABI nested_exception
|
|
|
|
{
|
|
|
|
exception_ptr __ptr_;
|
|
|
|
public:
|
2011-05-26 20:23:59 +02:00
|
|
|
nested_exception() _NOEXCEPT;
|
|
|
|
// nested_exception(const nested_exception&) noexcept = default;
|
|
|
|
// nested_exception& operator=(const nested_exception&) noexcept = default;
|
|
|
|
virtual ~nested_exception() _NOEXCEPT;
|
2010-05-27 19:06:52 +02:00
|
|
|
|
|
|
|
// access functions
|
2011-05-26 19:07:32 +02:00
|
|
|
_ATTRIBUTE(noreturn) void rethrow_nested() const;
|
2011-05-26 20:23:59 +02:00
|
|
|
_LIBCPP_INLINE_VISIBILITY exception_ptr nested_ptr() const _NOEXCEPT {return __ptr_;}
|
2010-05-27 19:06:52 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class _Tp>
|
|
|
|
struct __nested
|
|
|
|
: public _Tp,
|
|
|
|
public nested_exception
|
|
|
|
{
|
2010-09-21 23:28:23 +02:00
|
|
|
_LIBCPP_INLINE_VISIBILITY explicit __nested(const _Tp& __t) : _Tp(__t) {}
|
2010-05-27 19:06:52 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class _Tp>
|
2011-05-26 19:07:32 +02:00
|
|
|
_ATTRIBUTE(noreturn)
|
2010-08-22 02:02:43 +02:00
|
|
|
void
|
2010-09-05 01:28:19 +02:00
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2011-05-26 19:07:32 +02:00
|
|
|
throw_with_nested(_Tp&& __t, typename enable_if<
|
2010-05-27 19:06:52 +02:00
|
|
|
is_class<typename remove_reference<_Tp>::type>::value &&
|
|
|
|
!is_base_of<nested_exception, typename remove_reference<_Tp>::type>::value
|
|
|
|
>::type* = 0)
|
2010-09-05 01:28:19 +02:00
|
|
|
#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-05-27 19:06:52 +02:00
|
|
|
throw_with_nested (_Tp& __t, typename enable_if<
|
|
|
|
is_class<_Tp>::value && !is_base_of<nested_exception, _Tp>::value
|
|
|
|
>::type* = 0)
|
2010-09-05 01:28:19 +02:00
|
|
|
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-05-27 19:06:52 +02:00
|
|
|
{
|
2010-08-11 19:04:31 +02:00
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
2011-06-30 23:18:19 +02:00
|
|
|
throw __nested<typename remove_reference<_Tp>::type>(_VSTD::forward<_Tp>(__t));
|
2010-08-11 19:04:31 +02:00
|
|
|
#endif
|
2010-05-27 19:06:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class _Tp>
|
2011-05-26 19:07:32 +02:00
|
|
|
_ATTRIBUTE(noreturn)
|
2010-08-22 02:02:43 +02:00
|
|
|
void
|
2010-09-05 01:28:19 +02:00
|
|
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2011-05-26 19:07:32 +02:00
|
|
|
throw_with_nested(_Tp&& __t, typename enable_if<
|
2010-05-27 19:06:52 +02:00
|
|
|
!is_class<typename remove_reference<_Tp>::type>::value ||
|
|
|
|
is_base_of<nested_exception, typename remove_reference<_Tp>::type>::value
|
|
|
|
>::type* = 0)
|
2010-09-05 01:28:19 +02:00
|
|
|
#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-05-27 19:06:52 +02:00
|
|
|
throw_with_nested (_Tp& __t, typename enable_if<
|
|
|
|
!is_class<_Tp>::value || is_base_of<nested_exception, _Tp>::value
|
|
|
|
>::type* = 0)
|
2010-09-05 01:28:19 +02:00
|
|
|
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
2010-05-27 19:06:52 +02:00
|
|
|
{
|
2010-08-11 19:04:31 +02:00
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
2011-06-30 23:18:19 +02:00
|
|
|
throw _VSTD::forward<_Tp>(__t);
|
2010-08-11 19:04:31 +02:00
|
|
|
#endif
|
2010-05-27 19:06:52 +02:00
|
|
|
}
|
|
|
|
|
2011-11-29 19:15:50 +01:00
|
|
|
template <class _Ep>
|
2010-09-21 23:28:23 +02:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2010-05-27 19:06:52 +02:00
|
|
|
void
|
2011-11-29 19:15:50 +01:00
|
|
|
rethrow_if_nested(const _Ep& __e, typename enable_if<
|
|
|
|
is_polymorphic<_Ep>::value
|
2010-05-27 19:06:52 +02:00
|
|
|
>::type* = 0)
|
|
|
|
{
|
2010-05-28 15:35:41 +02:00
|
|
|
const nested_exception* __nep = dynamic_cast<const nested_exception*>(&__e);
|
|
|
|
if (__nep)
|
|
|
|
__nep->rethrow_nested();
|
2010-05-27 19:06:52 +02:00
|
|
|
}
|
|
|
|
|
2011-11-29 19:15:50 +01:00
|
|
|
template <class _Ep>
|
2010-09-21 23:28:23 +02:00
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
2010-05-27 19:06:52 +02:00
|
|
|
void
|
2011-12-01 21:21:04 +01:00
|
|
|
rethrow_if_nested(const _Ep&, typename enable_if<
|
2011-11-29 19:15:50 +01:00
|
|
|
!is_polymorphic<_Ep>::value
|
2010-05-27 19:06:52 +02:00
|
|
|
>::type* = 0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-05-11 21:42:16 +02:00
|
|
|
} // std
|
|
|
|
|
|
|
|
#endif // _LIBCPP_EXCEPTION
|