Functie restore_exception_handler

De functie restore_exception_handler herstelt de vorige uitzonderingshandler, die was vervangen met behulp van set_exception_handler. Deze functie accepteert geen parameters en retourneert geen waarden.

Syntaxis

phprestore_exception_handler();

Voorbeeld

Laten we een aangepaste uitzonderingshandler instellen en vervolgens de vorige herstellen:

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

Voorbeeld

Laten we controleren of na het herstellen van de handler het standaardmechanisme werkt:

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

Resultaat van code-uitvoering:

php'Handler 1: Testfout'