Funkcija restore_exception_handler

Funkcija restore_exception_handler atkuria ankstesnį išimčių tvarkytuvą, kuris buvo pakeistas naudojant set_exception_handler. Ši funkcija nepriima parametrų ir negrąžina jokių reikšmių.

Sintaksė

phprestore_exception_handler();

Pavyzdys

Nustatykime pasirinktinį išimčių tvarkytuvą, o tada atkurkime ankstesnį:

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

Pavyzdys

Patikrinkime, kad po tvarkytuvo atkūrimo veikia standartinis mechanizmas:

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('Test error');
?>

Kodo vykdymo rezultatas:

php'Handler 1: Test error'