Fungsi restore_exception_handler

Fungsi restore_exception_handler memulihkan penangan pengecualian sebelumnya, yang telah diganti menggunakan set_exception_handler. Fungsi ini tidak menerima parameter dan tidak mengembalikan nilai.

Sintaks

phprestore_exception_handler();

Contoh

Mari kita atur penangan pengecualian kustom, lalu pulihkan yang sebelumnya:

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

Contoh

Mari kita periksa bahwa setelah memulihkan penangan, mekanisme standar berfungsi:

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

Hasil eksekusi kode:

php'Handler 1: Test error'