名前空間
変種
操作

std::rethrow_exception

提供: cppreference.com
< cpp‎ | error
 
 
ユーティリティライブラリ
汎用ユーティリティ
日付と時間
関数オブジェクト
書式化ライブラリ (C++20)
(C++11)
関係演算子 (C++20で非推奨)
整数比較関数
(C++20)
スワップと型操作
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
一般的な語彙の型
(C++11)
(C++17)
(C++17)
(C++17)
(C++17)

初等文字列変換
(C++17)
(C++17)
 
エラー処理
例外処理
rethrow_exception
(C++11)
例外処理の失敗
(C++17未満)
(C++17未満)
(C++11)(C++17未満)
(C++17未満)
エラー番号
エラー番号
 
ヘッダ <exception> で定義
[[noreturn]] void rethrow_exception( std::exception_ptr p )
(C++11以上)

例外ポインタ p によって参照されている、以前にキ���プチャされた例外オブジェクトを投げます。

目次

[編集] 引数

p - ヌルでない std::exception_ptr

[編集] 戻り値

(なし)

[編集]

#include <iostream>
#include <string>
#include <exception>
#include <stdexcept>
 
void handle_eptr(std::exception_ptr eptr) // passing by value is ok
{
    try {
        if (eptr) {
            std::rethrow_exception(eptr);
        }
    } catch(const std::exception& e) {
        std::cout << "Caught exception \"" << e.what() << "\"\n";
    }
}
 
int main()
{
    std::exception_ptr eptr;
    try {
        std::string().at(1); // this generates an std::out_of_range
    } catch(...) {
        eptr = std::current_exception(); // capture
    }
    handle_eptr(eptr);
} // destructor for std::out_of_range called here, when the eptr is destructed

出力:

Caught exception "basic_string::at"

[編集] 関連項目

例外オブジェクトを扱うための共有ポインタ型
(typedef) [edit]
現在の例外を std::exception_ptr にキャプチャします
(関数) [edit]