namespace std {
class nested_exception {
public:
nested_exception() noexcept;
nested_exception(const nested_exception&) noexcept = default;
nested_exception& operator=(const nested_exception&) noexcept = default;
virtual ~nested_exception() = default;
// access functions
[[noreturn]] void rethrow_nested() const;
exception_ptr nested_ptr() const noexcept;
};
template<class T> [[noreturn]] void throw_with_nested(T&& t);
template <class E> void rethrow_if_nested(const E& e);
}
Класс nested_exception предназначен для использования в качестве миксина посредством множественного наследования. Он фиксирует текущее обрабатываемое исключение и сохраняет его для дальнейшего использования.
[ Note: nested_exception имеет виртуальный деструктор, чтобы сделать его полиморфным классом. Его наличие можно проверить с помощью dynamic_cast. ] — end note
nested_exception() noexcept;
[[noreturn]] void rethrow_nested() const;
Effects: Если nested_ptr() возвращает нулевой указатель, функция вызывает std::terminate(). В противном случае он генерирует сохраненное исключение, захваченное *this.
exception_ptr nested_ptr() const noexcept;
template <class T> [[noreturn]] void throw_with_nested(T&& t);
Throws: Если is_class_v<U> && !is_final_v<U> && !is_base_of_v<nested_exception, U> это true, исключение неопределенного типа , который публично производный от обоего U и nested_exception и построенного std::forward<T>(t), в противном случае std::forward<T>(t).
template <class E> void rethrow_if_nested(const E& e);