PHP set_exception_handler()ฟังก์ชั่น
ตัวอย่าง
ตั้งค่าฟังก์ชันตัวจัดการข้อยกเว้นที่ผู้ใช้กำหนด:
<?php
// A user-defined exception handler function
function myException($exception)
{
echo "<b>Exception:</b> ", $exception->getMessage();
}
// Set user-defined exception handler function
set_exception_handler("myException");
// Throw exception
throw new Exception("Uncaught exception occurred!");
?>
ความหมายและการใช้งาน
ฟังก์ชัน set_exception_handler() ตั้งค่าฟังก์ชันตัวจัดการข้อยกเว้นที่ผู้ใช้กำหนด
สคริปต์จะหยุดทำงานหลังจากเรียกตัวจัดการข้อยกเว้น
ไวยากรณ์
set_exception_handler(exceptionhandler);
ค่าพารามิเตอร์
Parameter | Description |
---|---|
exceptionhandler | Required. Specifies the name of the function to be run when an uncaught exception occurs. NULL can be passed instead, to reset this handler to its default state |
รายละเอียดทางเทคนิค
คืนมูลค่า: | สตริงที่มีตัวจัดการข้อยกเว้นที่กำหนดไว้ก่อนหน้านี้ หรือ NULL เนื่องจากข้อผิดพลาดหรือหากไม่มีการกำหนดตัวจัดการก่อนหน้านี้ |
---|---|
รุ่น PHP: | 5.0+ |
บันทึกการเปลี่ยนแปลง PHP: | ก่อนหน้านี้ หากผ่าน NULL ฟังก์ชันนี้จะคืนค่า TRUE ส่งคืนตัวจัดการก่อนหน้าตั้งแต่ PHP 5.5 |
การอ้างอิงข้อผิดพลาด PHP