Condividi tramite


set_terminate (<exception>)

Stabilisce nuovo terminate_handler da chiamare alla chiusura del programma.

terminate_handler
   set_terminate(
      terminate_handler _Pnew
   ) throw( );

Parametri

  • _Pnew
    Funzione da chiamare alla chiusura.

Valore restituito

L'indirizzo della funzione precedente che ha utilizzato per essere chiamata alla chiusura.

Note

La funzione crea nuovo terminate_handler come il *_Pnew di funzione.Pertanto, il _Pnew non deve essere un puntatore null.La funzione restituisce l'indirizzo del precedente termina il gestore.

Esempio

// exception_set_terminate.cpp
// compile with: /EHsc /c
#include<exception>
#include<iostream>

using namespace std;

void termfunction( ) 
{
   cout << "I'll be back." << endl;
   abort( );
}

int main( ) 
{
   terminate_handler oldHand = set_terminate(termfunction);

   // Throwing an unhandled exception would also terminate the program
   throw bad_alloc( );

   // The program could also be explicitely terminated with:
   // terminate( );
}
  
  
  

Requisiti

intestazione: <exception>

Spazio dei nomi: deviazione standard