Skip to content

Latest commit

 

History

History
92 lines (71 loc) · 2.76 KB

File metadata and controls

92 lines (71 loc) · 2.76 KB

rethrow_exception

  • exception[meta header]
  • std[meta namespace]
  • function[meta id-type]
  • cpp11[meta cpp]
[[noreturn]] void rethrow_exception(exception_ptr p);           // (1) C++11
[[noreturn]] constexpr void rethrow_exception(exception_ptr p); // (1) C++26
  • exception_ptr[link exception_ptr.md]

概要

exception_ptrが指す例外オブジェクトを再送出する。

事前条件

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

効果

説明用の変数uを、pが指す例外オブジェクトもしくはそのコピーとする。 コピーが行われるか否か、コピー時にメモリ確保が行われるか否かは未規定とされる。

  • u用のメモリ確保に失敗した場合、bad_alloc例外が送出される。
  • そうでなければ、pが指す例外オブジェクトからuへのコピー時に例外送出された場合、その例外が送出される。
  • そうでなければ、throw u;

戻り値

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

#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

処理系

  • Clang: ??
  • GCC: 4.6.1 [mark verified]
  • ICC: ??
  • Visual C++: 2010 [mark verified], 2012 [mark verified], 2013 [mark verified], 2015 [mark verified]

関連項目

参照