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
75 [[__gnu__::__gnu_inline__]]
78 virtual ~nested_exception() noexcept;
83 _GLIBCXX26_CONSTEXPR
void
99 template<
typename _Except>
100 struct _Nested_exception :
public _Except,
public nested_exception
102 _GLIBCXX26_CONSTEXPR
explicit _Nested_exception(
const _Except& __ex)
106 _GLIBCXX26_CONSTEXPR
explicit _Nested_exception(_Except&& __ex)
107 : _Except(static_cast<_Except&&>(__ex))
111#if __cplusplus < 201703L || ! defined __cpp_if_constexpr
115 template<
typename _Tp>
118 __throw_with_nested_impl(_Tp&& __t,
true_type)
123 template<
typename _Tp>
126 __throw_with_nested_impl(_Tp&& __t,
false_type)
153 template<
typename _Tp>
155 _GLIBCXX26_CONSTEXPR
inline void
158 using _Up =
typename decay<_Tp>::type;
159 using _CopyConstructible
161 static_assert(_CopyConstructible::value,
162 "throw_with_nested argument must be CopyConstructible");
164#if __cplusplus >= 201703L && __cpp_if_constexpr
165 if constexpr (is_class_v<_Up>)
166 if constexpr (!is_final_v<_Up>)
167 if constexpr (!is_base_of_v<nested_exception, _Up>)
171 using __nest = __and_<is_class<_Up>, __bool_constant<!__is_final(_Up)>,
172 __not_<is_base_of<nested_exception, _Up>>>;
177#if __cplusplus < 201703L || ! defined __cpp_if_constexpr
181 template<
typename _Ex>
183 __rethrow_if_nested_impl(
const _Ex* __ptr, true_type)
185 if (
auto __ne_ptr =
dynamic_cast<const nested_exception*
>(__ptr))
186 __ne_ptr->rethrow_nested();
191 __rethrow_if_nested_impl(
const void*,
false_type)
211 template<
typename _Ex>
213 [[__gnu__::__always_inline__]]
215 _GLIBCXX26_CONSTEXPR
inline void
218 const _Ex* __ptr = __builtin_addressof(__ex);
219#if __cplusplus < 201703L || ! defined __cpp_if_constexpr
221 using __cast = __and_<is_polymorphic<_Ex>,
222 __or_<__not_<is_base_of<nested_exception, _Ex>>,
223 is_convertible<_Ex*, nested_exception*>>>;
225 using __cast = __and_<is_polymorphic<_Ex>,
227 is_convertible<_Ex*, nested_exception*>>;
229 std::__rethrow_if_nested_impl(__ptr, __cast{});
231 if constexpr (!is_polymorphic_v<_Ex>)
233 else if constexpr (is_base_of_v<nested_exception, _Ex>
234 && !is_convertible_v<_Ex*, nested_exception*>)
237 else if constexpr (!is_base_of_v<nested_exception, _Ex>)
241 __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).