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
restore_exception_handler();
Contoh
Mari kita atur penangan pengecualian kustom, lalu pulihkan yang sebelumnya:
<?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
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:
'Handler 1: Test error'