Skip to content

Latest commit

 

History

History
78 lines (59 loc) · 1.67 KB

File metadata and controls

78 lines (59 loc) · 1.67 KB

rethrow_exception

  • exception[meta header]
  • std[meta namespace]
  • function[meta id-type]
  • cpp11[meta cpp]
[[noreturn]] void rethrow_exception(exception_ptr p);

概要

exception_ptrが指す例外オブジェクトを再スローする。

要件

pがヌルを指すexception_ptrではないこと。

戻り値

この関数は決して返らない。

#include <iostream>
#include <exception>
#include <stdexcept>

int main()
{
  std::exception_ptr ep;

  try {
    throw std::runtime_error("error!");
  }
  catch (...) {
    std::cout << "catch" << std::endl;
    ep = std::current_exception(); // 処理中の例外ポインタを取得
  }

  if (ep) {
    std::cout << "rethrow" << std::endl;
    std::rethrow_exception(ep); // 再スロー
  }
}
  • std::rethrow_exception[color ff0000]
  • std::exception_ptr[link exception_ptr.md]
  • std::runtime_error[link /reference/stdexcept.md]
  • std::current_exception()[link current_exception.md]

出力例

catch
rethrow

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
terminate called after throwing an instance of 'std::runtime_error'
  what():  error!

バージョン

言語

  • C++11

処理系

参照