◐ Shell
clean mode source ↗

std::set_terminate - cppreference.com

提供: cppreference.com

<tbody> </tbody> <tbody class="t-dcl-rev "> </tbody><tbody> </tbody>

ヘッダ <exception> で定義

std::terminate_handler set_terminate( std::terminate_handler f ) throw();

(C++11未満)

std::terminate_handler set_terminate( std::terminate_handler f ) noexcept;

(C++11以上)

f を新しいグローバルな終了ハンドラに設定し、以前設定されていた std::terminate_handler を返します。

この関数はスレッドセーフです。 std::set_terminate のすべての呼び出しは後続の std::set_terminate および std::get_terminate に対して同期します (std::memory_order を参照してください)。

(C++11以上)

引数

f - std::terminate_handler 型の関数へのポインタ、またはヌルポインタ

戻り値

以前設定した終了ハンドラ、または何も設定されていなければヌルポインタ値。

#include <iostream>
#include <cstdlib>
#include <exception>
   
int main()
{
    std::set_terminate([](){ std::cout << "Unhandled exception\n"; std::abort();});
    throw 1;
}

出力例:

Unhandled exception
bash: line 7:  7743 Aborted                 (core dumped) ./a.out

関連項目