terminate (CRT)

abort를 사용하여 set_terminate 또는 사용자가 지정하는 함수를 호출합니다.

구문

void terminate( void );

설명

terminate 함수는 C++ 예외 처리와 함께 사용되며 다음과 같은 경우에 호출됩니다.

  • throw된 C++ 예외에 대해 일치하는 catch 처리기를 찾을 수 없습니다.

  • 스택 해제 중에 소멸자 함수가 예외를 throw한 경우

  • 스택이 예외를 throw한 후에 손상된 경우

terminate는 기본적으로 abort를 호출합니다. 종료 함수를 직접 작성하고 함수 이름을 인수로 사용해 set_terminate를 호출하면 이 기본값을 변경할 수 있습니다. terminateset_terminate에 대한 인수로 지정된 마지막 함수를 호출합니다. 자세한 내용은 처리되지 않은 C++ 예외를 참조하세요.

기본적으로 이 함수의 전역 상태는 애플리케이션으로 범위가 지정됩니다. 이 동작을 변경하려면 CRT의 전역 상태를 참조하세요.

요구 사항

루틴에서 반환된 값 필수 헤더
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);
}
term_func() was called by terminate().

참고 항목

예외 처리 루틴
abort
_set_se_translator
set_terminate
set_unexpected
unexpected