30#ifndef _GLIBCXX_NESTED_EXCEPTION_H
31#define _GLIBCXX_NESTED_EXCEPTION_H 1
33#if __cplusplus < 201103L
42namespace std _GLIBCXX_VISIBILITY(default)
74#if __cplusplus >= 202400L
77 virtual ~nested_exception() noexcept;
82 _GLIBCXX26_CONSTEXPR
void
98 template<
typename _Except>
99 struct _Nested_exception :
public _Except,
public nested_exception
101 _GLIBCXX26_CONSTEXPR
explicit _Nested_exception(
const _Except& __ex)
105 _GLIBCXX26_CONSTEXPR
explicit _Nested_exception(_Except&& __ex)
106 : _Except(static_cast<_Except&&>(__ex))
110#if __cplusplus < 201703L || ! defined __cpp_if_constexpr
114 template<
typename _Tp>
117 __throw_with_nested_impl(_Tp&& __t,
true_type)
122 template<
typename _Tp>
125 __throw_with_nested_impl(_Tp&& __t,
false_type)
152 template<
typename _Tp>
154 _GLIBCXX26_CONSTEXPR
inline void
157 using _Up =
typename decay<_Tp>::type;
158 using _CopyConstructible
160 static_assert(_CopyConstructible::value,
161 "throw_with_nested argument must be CopyConstructible");
163#if __cplusplus >= 201703L && __cpp_if_constexpr
164 if constexpr (is_class_v<_Up>)
165 if constexpr (!is_final_v<_Up>)
166 if constexpr (!is_base_of_v<nested_exception, _Up>)
170 using __nest = __and_<is_class<_Up>, __bool_constant<!__is_final(_Up)>,
171 __not_<is_base_of<nested_exception, _Up>>>;
176#if __cplusplus < 201703L || ! defined __cpp_if_constexpr
180 template<
typename _Ex>
182 __rethrow_if_nested_impl(
const _Ex* __ptr, true_type)
184 if (
auto __ne_ptr =
dynamic_cast<const nested_exception*
>(__ptr))
185 __ne_ptr->rethrow_nested();
190 __rethrow_if_nested_impl(
const void*,
false_type)
210 template<
typename _Ex>
212 [[__gnu__::__always_inline__]]
214 _GLIBCXX26_CONSTEXPR
inline void
217 const _Ex* __ptr = __builtin_addressof(__ex);
218#if __cplusplus < 201703L || ! defined __cpp_if_constexpr
220 using __cast = __and_<is_polymorphic<_Ex>,
221 __or_<__not_<is_base_of<nested_exception, _Ex>>,
222 is_convertible<_Ex*, nested_exception*>>>;
224 using __cast = __and_<is_polymorphic<_Ex>,
226 is_convertible<_Ex*, nested_exception*>>;
228 std::__rethrow_if_nested_impl(__ptr, __cast{});
230 if constexpr (!is_polymorphic_v<_Ex>)
232 else if constexpr (is_base_of_v<nested_exception, _Ex>
233 && !is_convertible_v<_Ex*, nested_exception*>)
236 else if constexpr (!is_base_of_v<nested_exception, _Ex>)
240 __ne_ptr->rethrow_nested();
__bool_constant< true > true_type
The type used as a compile-time boolean with true value.
__bool_constant< false > false_type
The type used as a compile-time boolean with false value.
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
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).