(0) exportieren Drucken
Alle erweitern
div
eof
Erweitern Minimieren
Dieser Artikel wurde noch nicht bewertet - Dieses Thema bewerten.

terminate (CRT)

Calls abort or a function you specify using set_terminate.


void terminate( void );

The terminate function is used with C++ exception handling and is called in the following cases:

  • A matching catch handler cannot be found for a thrown C++ exception.

  • An exception is thrown by a destructor function during stack unwind.

  • The stack is corrupted after throwing an exception.

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 C++ Exceptions.

Routine Required header Compatibility

terminate

<eh.h>

ANSI, Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003

For additional compatibility information, see Compatibility in the Introduction.

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

Output

term_func() was called by terminate().

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

Fanden Sie dies hilfreich?
(1500 verbleibende Zeichen)
Vielen Dank für Ihr Feedback.
Anzeigen:
© 2014 Microsoft. Alle Rechte vorbehalten.