Hàm restore_exception_handler

Hàm restore_exception_handler khôi phục bộ xử lý ngoại lệ trước đó, vốn đã bị thay thế bằng cách sử dụng set_exception_handler. Hàm này không nhận tham số và không trả về giá trị.

Cú pháp

phprestore_exception_handler();

Ví dụ

Hãy thiết lập một bộ xử lý ngoại lệ tùy chỉnh, sau đó khôi phục bộ xử lý trước đó:

php<?php
  function customExceptionHandler($exception) {
    echo 'Bộ xử lý tùy chỉnh: ' . $exception->getMessage();
  }
  
  set_exception_handler('customExceptionHandler');
  restore_exception_handler();
?>

Ví dụ

Hãy kiểm tra xem sau khi khôi phục bộ xử lý, cơ chế tiêu chuẩn có hoạt động không:

php<?php
  set_exception_handler(function($exception) {
    echo 'Bộ xử lý 1: ' . $exception->getMessage();
  });
  
  set_exception_handler(function($exception) {
    echo 'Bộ xử lý 2: ' . $exception->getMessage();
  });
  
  restore_exception_handler();
  throw new Exception('Lỗi kiểm tra');
?>

Kết quả thực thi mã:

php'Bộ xử lý 1: Lỗi kiểm tra'