用法
string set_exception_handler ( callback $exception_handler );
定義和用法
如果在 try/catch 塊中未捕獲異常,則此函數設置默認異常處理程序。調用 exception_handler 後將停止執行。
參數
Sr.No | 參數及說明 |
---|---|
1 |
exception_handler 發生未捕獲的異常時要調用的函數的名稱。該函數必須在調用 set_exception_handler() 之前定義。此處理函數需要接受一個參數,即拋出的異常對象。 |
返回值
它返回先前定義的異常處理程序的名稱,或者在出錯時返回 NULL。如果之前未定義處理程序,則還返回 NULL。
示例
下麵是這個函數的用法~
<?php
function exception_handler($exception) {
echo "Uncaught exception is:" , $exception->getMessage(), "\n";
}
set_exception_handler('exception_handler');
set_exception_handler();
throw new Exception('Not Found Exception');
echo "not included Executed\n";
?>
這將產生以下結果 -
Uncaught exception is:Not Found Exception
相關用法
- PHP set_exception_handler()用法及代碼示例
- PHP set_error_handler()用法及代碼示例
- PHP set_file_buffer()用法及代碼示例
- PHP Spreadsheet_Excel_Writer setAlign()用法及代碼示例
- PHP Spreadsheet_Excel_Writer setScript()用法及代碼示例
- PHP Spreadsheet_Excel_Writer setOutLine()用法及代碼示例
- PHP Spreadsheet_Excel_Writer setColor()用法及代碼示例
- PHP Spreadsheet_Excel_Writer setFontFamily()用法及代碼示例
- PHP setlocale()用法及代碼示例
- PHP Spreadsheet_Excel_Writer setTextWrap()用法及代碼示例
- PHP Spreadsheet_Excel_Writer setItalic()用法及代碼示例
- PHP Spreadsheet_Excel_Writer setVAlign()用法及代碼示例
- PHP Spreadsheet_Excel_Writer setBgColor()用法及代碼示例
- PHP settype()用法及代碼示例
- PHP Spreadsheet_Excel_Writer setHAlign()用法及代碼示例
- PHP Spreadsheet_Excel_Writer setFgColor()用法及代碼示例
- PHP Spreadsheet_Excel_Writer setShadow()用法及代碼示例
- PHP Spreadsheet_Excel_Writer setBold()用法及代碼示例
- PHP Spreadsheet_Excel_Writer setStrikeOut()用法及代碼示例
- PHP Spreadsheet_Excel_Writer setUnderline()用法及代碼示例
注:本文由純淨天空篩選整理自 PHP - Function set_exception_handler()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。