- exception[meta header]
- std[meta namespace]
- nested_exception[meta class]
- function[meta id-type]
- cpp11[meta cpp]
nested_exception() noexcept; // (1) C++11
nested_exception(const nested_exception&) noexcept = default; // (2) C++11- (1) :
current_exception()を呼び出し、その戻り値をメンバ変数として保持する。
投げない
#include <exception>
#include <iostream>
class my_exception : public std::nested_exception {};
int main()
{
try {
try {
throw 1;
}
catch (int& x) {
my_exception e; // 現在の例外(int)が保持される
// my_exceptionによって入れ子になった例外へのポインタを取得して再送出
std::rethrow_exception(e.nested_ptr());
}
}
catch (int& x) {
std::cout << x << std::endl;
}
} - nested_ptr()[link nested_ptr.md]
- std::rethrow_exception[link /reference/exception/rethrow_exception.md]
1
- C++11
- Clang: ??
- GCC: 3 [mark verified]
- GCC: 4.7.0 [mark verified]
- ICC: ??
- Visual C++: 2015 [mark verified]
- P3842R2 A conservative fix for constexpr
uncaught_exceptions()andcurrent_exception()- C++26の策定中に
constexprが追加されたが、本提案文書により巻き戻された (C++29で再検討予定)
- C++26の策定中に