terminate (CRT)

呼叫 abort 或使用 set_terminate 指定的您的函式。

void terminate( void );

備註

terminate 函式使用 C++ 例外狀況處理和在下列情況下呼叫:

  • 符合 catch 處理常式不能為擲回的 C++ 例外狀況中找到。

  • 例外狀況是由解構函式擲回堆疊回溯期間。

  • 堆疊在擲回例外狀況後已損毀。

根據預設,terminate 會呼叫 abort。 您可以撰寫自己的終止函式和以 set_terminate 作為引數呼叫您的自訂的函式名稱函數以變更此預設。 terminate會呼叫指定的最後一個函式做為 set_terminate 的引數。 如需詳細資訊,請參閱未處理的 C++ 例外狀況

需求

常式

必要的標頭

terminate

<eh.h>

如需其他相容性資訊,請參閱<簡介>中的相容性

範例

// 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);
}
  

.NET Framework 對等用法

不適用。若要呼叫標準 C 函式,請使用 PInvoke。如需詳細資訊,請參閱平台叫用範例

請參閱

參考

例外狀況處理常式

abort

_set_se_translator

set_terminate (CRT)

set_unexpected (CRT)

unexpected (CRT)