(Yaf >=1.0.0)
Yaf_Dispatcher::catchException — 開啟/關(guān)閉自動異常捕獲功能
當 application.dispatcher.throwException 開啟的時候(你也可以通過調(diào)用 Yaf_Dispatcher::throwException(TRUE)() 來開啟它),Yaf將會拋出異常而不是觸發(fā)異常發(fā)生。
如果開啟了 Yaf_Dispatcher::catchException() (可以通過設(shè)置application.dispatcher.catchException來開啟),并且在你定義了異常處理的controller的情況下,Yaf會將所有未捕獲的異常交給Error Controller的Error Action來處理。
flag
bool
示例 #1 Yaf_Dispatcher::catchException()example
/* if you defined a ErrorController like following */
<?php
class ErrorController extends Yaf_Controller_Abstract {
/**
* you can also call to Yaf_Request_Abstract::getException to get the
* un-caught exception.
*/
public function error($exception) {
/* error occurs */
switch ($exception->getCode()) {
case YAF_ERR_NOTFOUND_MODULE:
case YAF_ERR_NOTFOUND_CONTROLLER:
case YAF_ERR_NOTFOUND_ACTION:
case YAF_ERR_NOTFOUND_VIEW:
echo 404, ":", $exception->getMessage();
break;
default :
$message = $exception->getMessage();
echo 0, ":", $exception->getMessage();
break;
}
}
}
?>
以上例程的輸出類似于:
/* now if some error occur, assuming access a non-exists controller(or you can throw a exception yourself): */ 404:Could not find controller script **/application/controllers/No-exists-controller.php