terminate (CRT)

abort、または set_terminate を使用して指定した関数を呼び出します。

構文

void terminate( void );

解説

terminate 関数が C++ 例外処理で使用され、次の場合に呼び出されます。

  • スローされた C++ 例外に対して一致する catch ハンドラーが見つかりません。

  • スタック アンワインド中にデストラクター関数によって例外がスローされた。

  • 例外をスローした後でスタックが破損した。

terminate は既定では abort を呼び出します。 この既定の設定を変更するには、独自の終了関数を作成し、その関数の名前を引数として set_terminate を呼び出します。 terminate は、set_terminate への引数として渡された最後の関数を呼び出します。 詳細については、「Unhandled C++ Exceptions」(ハンドルされない C++ 例外) を参照してください。

既定では、この関数のグローバル状態の適用対象は、アプリケーションになります。 この動作を変更するには、「CRT のグローバル状態」を参照してください

必要条件

ルーチンによって返される値 必須ヘッダー
terminate <eh.h>

互換性の詳細については、「 Compatibility」を参照してください。

// crt_terminate.cpp
// compile with: /EHsc
#include <eh.h>
#include <process.h>
#include <iostream>
using namespace std;

void term_func();

int main()
{
    int i = 10, j = 0, result;
    set_terminate( term_func );
    try
    {
        if( j == 0 )
            throw "Divide by zero!";
        else
            result = i/j;
    }
    catch( int )
    {
        cout << "Caught some integer exception.\n";
    }
    cout << "This should never print.\n";
}

void term_func()
{
    cout << "term_func() was called by terminate().\n";

    // ... cleanup tasks performed here

    // If this function does not exit, abort is called.

    exit(-1);
}
term_func() was called by terminate().

関連項目

例外処理ルーチン
abort
_set_se_translator
set_terminate
set_unexpected
unexpected