PHP set_exception_handler () function
Definisi dan Penggunaan
set_exception_handler () berfungsi untuk mengatur pengecualian handler user-didefinisikan.
Fungsi ini digunakan untuk membuat pengguna selama menjalankan penanganan eksepsi mereka sendiri.
Fungsi ini mengembalikan pengecualian handler lama jika gagal untuk kembali NULL.
tatabahasa
set_exception_handler(exception_function)
参数 | 描述 |
---|---|
exception_function | 必需。规定未捕获的异常发生时调用的函数。 该函数必须在调用 set_exception_handler() 函数之前定义。这个异常处理函数需要需要一个参数,即抛出的 exception 对象。 |
Tips dan Catatan
Tip: Setelah handler pengecualian dipanggil, script akan berhenti mengeksekusi.
contoh
<?php
function myException($exception)
{
echo "<b>Exception:</b> " , $exception->getMessage();
}
set_exception_handler('myException');
throw new Exception('Uncaught Exception occurred');
?>
function myException($exception)
{
echo "<b>Exception:</b> " , $exception->getMessage();
}
set_exception_handler('myException');
throw new Exception('Uncaught Exception occurred');
?>
Output dari kode di atas adalah sebagai berikut:
Exception:Uncaught Exception occurred
Lengkap PHP Kesalahan Referensi