Funzione restore_exception_handler

La funzione restore_exception_handler ripristina il gestore delle eccezioni precedente, che è stato sostituito tramite set_exception_handler. Questa funzione non accetta parametri e non restituisce valori.

Sintassi

phprestore_exception_handler();

Esempio

Impostiamo un gestore di eccezioni personalizzato e poi ripristiniamo quello precedente:

php<?php
  function customExceptionHandler($exception) {
    echo 'Gestore personalizzato: ' . $exception->getMessage();
  }
  
  set_exception_handler('customExceptionHandler');
  restore_exception_handler();
?>

Esempio

Verifichiamo che dopo il ripristino del gestore funzioni il meccanismo standard:

php<?php
  set_exception_handler(function($exception) {
    echo 'Gestore 1: ' . $exception->getMessage();
  });
  
  set_exception_handler(function($exception) {
    echo 'Gestore 2: ' . $exception->getMessage();
  });
  
  restore_exception_handler();
  throw new Exception('Errore di test');
?>

Risultato dell'esecuzione del codice:

php'Gestore 1: Errore di test'