std::rethrow_exception
提供: cppreference.com
ヘッダ <exception> で定義
|
||
[[noreturn]] void rethrow_exception( std::exception_ptr p ) |
(C++11以上) | |
例外ポインタ p
によって参照されている、以前にキ���プチャされた例外オブジェクトを投げます。
目次 |
[編集] 引数
p | - | ヌルでない std::exception_ptr |
[編集] 戻り値
(なし)
[編集] 例
Run this code
#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"
[編集] 関連項目
(C++11) |
例外オブジェクトを扱うための共有ポインタ型 (typedef) |
(C++11) |
現在の例外を std::exception_ptr にキャプチャします (関数) |