1 <?php
2
3 function handleMissedException($e) {
4 echo "Sorry, something is wrong. Please try again, or contact us if the problem persists. Thanks!";
5 //error_log($str);//保存一條錯誤信息字符串到web服務器的error_log文檔裡。
6 error_log('Unhandled Exception:' . $e->getMessage() . 'in file' . $e->getFile() . 'on line' . $e->getLine());
7 }
8
9 set_exception_handler('handleMissedException');
10
11 //測試拋出一個錯誤。
12 throw new Exception('just testing');
13
14 //整個測試程序就這麼多。
15 //上下文都沒有catch。所以會觸發 handleMissedExceotion($e)函數, $e為Exception或Exception的子類
error_log存在web服務器的error_log裡。
例如:apache可以在配置文件httpd.conf中搜error_log找到它的位置。