?
剛才已經說過了set_error_handler這個函數,作用就是自定義錯誤處理,
那么現在就來簡單的說一下set_exception_handler,看名字我們就能發現,這說的是自定義異常處理。
呵呵,我聰明吧?來,先看一下調用方法:
string set_exception_handler ( callback $exception_handler )
?
同樣是在看TP代碼的時候發現的這個函數,就想不明白了,自己以前咋就沒關心過這些東西呢?(捶胸頓足ing。。。) 繼續來看一下TP是怎么實現的,呃,為啥一定要用TP呢,嗯。那好吧,一會兒我把手冊的例子也搬過來。 public function appException($e) { halt($e->__toString()); } set_exception_handler(array(&$this,"appException")); 呵呵,這個簡單吧?因為我沒有給出halt這個方法的實現,這樣就足夠了。 再看手冊中的例子, function exception_handler($exception) { echo "Uncaught exception: " , $exception->getMessage(), "/n"; } set_exception_handler('exception_handler'); throw new Exception('Uncaught Exception'); echo "Not Executed/n"; 其實呢,set_exception_handler就是設置了一下,當你的程序需要拋出一個異常的時候調用哪個自定義的函數。 就這么簡單?
?