terminate (CRT)
调用 abort 或使用 set_terminate 指定的函数。
void terminate( void );
备注
C++ 异常处理使用 terminate 函数,在下列情况下调用:
匹配的捕获处理程序无法找到一个抛出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。有关更多信息,请参见平台调用示例。