Calls abort or a function you specify using set_terminate.
void terminate( void );
Routine | Required Header | Compatibility |
terminate | <eh.h> | ANSI, Win 95, Win NT |
For additional compatibility information, see Compatibility in the Introduction.
Libraries
LIBC.LIB | Single thread static library, retail version |
LIBCMT.LIB | Multithread static library, retail version |
MSVCRT.LIB | Import library for MSVCRT.DLL, retail version |
Return Value
None
Remarks
The terminate function is used with C++ exception handling and is called in the following cases:
terminate calls abort by default. You can change this default by writing your own termination function and calling set_terminate with the name of your function as its argument. terminate calls the last function given as an argument to set_terminate. For more information, see Unhandled Exceptions.
Example
/* TERMINAT.CPP:
*/
#include <eh.h>
#include <process.h>
#include <iostream.h>
void term_func();
void 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);
}
Output
term_func() was called by terminate().
See Also abort, _set_se_translator, set_terminate, set_unexpected, unexpected