最終更新日時(UTC):
が更新

履歴 編集

function
<exception>

std::set_terminate

namespace std {
  using terminate_handler = void(*)();
  terminate_handler set_terminate(terminate_handler f) noexcept;
}

概要

例外をキャッチされなかった場合に実行される終了ハンドラを設定する。

戻り値

前に設定されていた終了ハンドラを返す。

例外

投げない

備考

引数としてヌルポインタが渡された場合、デフォルトの終了ハンドラが設定される。

終了ハンドラは、呼び出し元に戻らずに異常終了すべきと規定されている。

#include <iostream>
#include <exception>

void my_terminate_handler()
{
  std::cout << "my terminate handler" << std::endl;
}

int main()
{
  std::set_terminate(my_terminate_handler);

  throw std::exception(); // no catch
}

出力例

my terminate handler

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

参照