30#ifndef _GLIBCXX_NESTED_EXCEPTION_H
31#define _GLIBCXX_NESTED_EXCEPTION_H 1
33#if __cplusplus < 201103L
42namespace std _GLIBCXX_VISIBILITY(default)
91 template<
typename _Except>
92 struct _Nested_exception :
public _Except,
public nested_exception
94 explicit _Nested_exception(
const _Except& __ex)
98 explicit _Nested_exception(_Except&& __ex)
99 : _Except(static_cast<_Except&&>(__ex))
103#if __cplusplus < 201703L || ! defined __cpp_if_constexpr
107 template<
typename _Tp>
110 __throw_with_nested_impl(_Tp&& __t,
true_type)
112 throw _Nested_exception<__remove_cvref_t<_Tp>>{std::forward<_Tp>(__t)};
115 template<
typename _Tp>
118 __throw_with_nested_impl(_Tp&& __t,
false_type)
119 {
throw std::forward<_Tp>(__t); }
145 template<
typename _Tp>
150 using _Up =
typename decay<_Tp>::type;
151 using _CopyConstructible
153 static_assert(_CopyConstructible::value,
154 "throw_with_nested argument must be CopyConstructible");
156#if __cplusplus >= 201703L && __cpp_if_constexpr
157 if constexpr (is_class_v<_Up>)
158 if constexpr (!is_final_v<_Up>)
159 if constexpr (!is_base_of_v<nested_exception, _Up>)
160 throw _Nested_exception<_Up>{std::forward<_Tp>(__t)};
161 throw std::forward<_Tp>(__t);
163 using __nest = __and_<is_class<_Up>, __bool_constant<!__is_final(_Up)>,
164 __not_<is_base_of<nested_exception, _Up>>>;
165 std::__throw_with_nested_impl(std::forward<_Tp>(__t), __nest{});
169#if __cplusplus < 201703L || ! defined __cpp_if_constexpr
173 template<
typename _Ex>
175 __rethrow_if_nested_impl(
const _Ex* __ptr,
true_type)
177 if (
auto __ne_ptr =
dynamic_cast<const nested_exception*
>(__ptr))
178 __ne_ptr->rethrow_nested();
183 __rethrow_if_nested_impl(
const void*,
false_type)
203 template<
typename _Ex>
205 [[__gnu__::__always_inline__]]
210 const _Ex* __ptr = __builtin_addressof(__ex);
211#if __cplusplus < 201703L || ! defined __cpp_if_constexpr
213 using __cast = __and_<is_polymorphic<_Ex>,
214 __or_<__not_<is_base_of<nested_exception, _Ex>>,
215 is_convertible<_Ex*, nested_exception*>>>;
217 using __cast = __and_<is_polymorphic<_Ex>,
219 is_convertible<_Ex*, nested_exception*>>;
221 std::__rethrow_if_nested_impl(__ptr, __cast{});
223 if constexpr (!is_polymorphic_v<_Ex>)
225 else if constexpr (is_base_of_v<nested_exception, _Ex>
226 && !is_convertible_v<_Ex*, nested_exception*>)
229 else if constexpr (!is_base_of_v<nested_exception, _Ex>)
233 __ne_ptr->rethrow_nested();
integral_constant< bool, true > true_type
The type used as a compile-time boolean with true value.
integral_constant< bool, false > false_type
The type used as a compile-time boolean with false value.
exception_ptr current_exception() noexcept
void rethrow_exception(exception_ptr)
Throw the object pointed to by the exception_ptr.
void terminate() noexcept
void rethrow_if_nested(const _Ex &__ex)
void throw_with_nested(_Tp &&__t)
ISO C++ entities toplevel namespace is std.
An opaque pointer to an arbitrary exception.
void rethrow_nested() const
Rethrow the stored exception, or terminate if none was stored.
exception_ptr nested_ptr() const noexcept
Access the stored exception.
nested_exception() noexcept
The default constructor stores the current exception (if any).