nested_exception() noexcept; // (1)
nested_exception(const nested_exception&) noexcept = default; // (2)
nested_exceptionオブジェクトの構築
- (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;
}
}
23
#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());
}
}
出力
1
バージョン
言語
- C++11
処理系
- Clang: ??
- GCC: 3 ✅
- GCC: 4.7.0 ✅
- ICC: ??
- Visual C++: 2015 ✅