109 lines
3.9 KiB
Markdown
109 lines
3.9 KiB
Markdown
[except.nested]
|
||
|
||
# 17 Language support library [[support]](./#support)
|
||
|
||
## 17.9 Exception handling [[support.exception]](support.exception#except.nested)
|
||
|
||
### 17.9.8 nested_exception [except.nested]
|
||
|
||
[ð](#lib:nested_exception)
|
||
|
||
namespace std {class nested_exception {public:constexpr nested_exception() noexcept; constexpr nested_exception(const nested_exception&) noexcept = default; constexpr nested_exception& operator=(const nested_exception&) noexcept = default; constexpr virtual ~nested_exception() = default; // access functions[[noreturn]] constexpr void rethrow_nested() const; constexpr exception_ptr nested_ptr() const noexcept; }; template<class T> [[noreturn]] constexpr void throw_with_nested(T&& t); template<class E> constexpr void rethrow_if_nested(const E& e);}
|
||
|
||
[1](#1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L4297)
|
||
|
||
The class nested_exception is designed for use as a mixin through
|
||
multiple inheritance[.](#1.sentence-1)
|
||
|
||
It captures the currently handled exception and stores it
|
||
for later use[.](#1.sentence-2)
|
||
|
||
[2](#2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L4302)
|
||
|
||
[*Note [1](#note-1)*:
|
||
|
||
nested_exception has a virtual destructor to make it a
|
||
polymorphic class[.](#2.sentence-1)
|
||
|
||
Its presence can be tested for with dynamic_cast[.](#2.sentence-2)
|
||
|
||
â *end note*]
|
||
|
||
[ð](#lib:nested_exception,constructor)
|
||
|
||
`constexpr nested_exception() noexcept;
|
||
`
|
||
|
||
[3](#3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L4314)
|
||
|
||
*Effects*: The constructor calls current_exception() and stores the returned value[.](#3.sentence-1)
|
||
|
||
[ð](#lib:rethrow_nested,nested_exception)
|
||
|
||
`[[noreturn]] constexpr void rethrow_nested() const;
|
||
`
|
||
|
||
[4](#4)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L4325)
|
||
|
||
*Effects*: If nested_ptr() returns a null pointer, the function calls the function std::terminate[.](#4.sentence-1)
|
||
|
||
Otherwise, it throws the stored exception captured by *this[.](#4.sentence-2)
|
||
|
||
[ð](#lib:nested_ptr,nested_exception)
|
||
|
||
`constexpr exception_ptr nested_ptr() const noexcept;
|
||
`
|
||
|
||
[5](#5)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L4337)
|
||
|
||
*Returns*: The stored exception captured by this nested_exception object[.](#5.sentence-1)
|
||
|
||
[ð](#lib:throw_with_nested,nested_exception)
|
||
|
||
`template<class T> [[noreturn]] constexpr void throw_with_nested(T&& t);
|
||
`
|
||
|
||
[6](#6)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L4348)
|
||
|
||
Let U be decay_t<T>[.](#6.sentence-1)
|
||
|
||
[7](#7)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L4351)
|
||
|
||
*Preconditions*: U meets the [*Cpp17CopyConstructible*](utility.arg.requirements#:Cpp17CopyConstructible "16.4.4.2 Template argument requirements [utility.arg.requirements]") requirements[.](#7.sentence-1)
|
||
|
||
[8](#8)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L4355)
|
||
|
||
*Throws*: If is_class_v<U> && !is_final_v<U> && !is_base_of_v<nested_exception, U> is true,
|
||
an exception of unspecified type that is publicly derived from bothU and nested_exception and constructed from std::forward<T>(t), otherwisestd::forward<T>(t)[.](#8.sentence-1)
|
||
|
||
[ð](#lib:rethrow_if_nested,nested_exception)
|
||
|
||
`template<class E> constexpr void rethrow_if_nested(const E& e);
|
||
`
|
||
|
||
[9](#9)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L4371)
|
||
|
||
*Effects*: If E is not a polymorphic class type, or
|
||
if nested_exception is an inaccessible or ambiguous base class of E,
|
||
there is no effect[.](#9.sentence-1)
|
||
|
||
Otherwise, performs:if (auto p = dynamic_cast<const nested_exception*>(addressof(e))) p->rethrow_nested();
|