Yaf_Dispatcher::catchException
Yaf_Dispatcher::catchException
(Yaf >=1.0.0)
Yaf_Dispatcher :: catchException - 打开/关闭异常捕获
描述
public Yaf_Dispatcher Yaf_Dispatcher::catchException ([ bool $flag ] )
虽然application.dispatcher.throwException处于开启状态(您也可以调用Yaf_Dispatcher :: throwException(TRUE)()
来启用它),但Yaf会抛出异常,因为错误发生而不是触发器错误。
那么如果你启用了Yaf_Dispatcher :: catchException()
(也可以通过设置application.dispatcher.catchException来启用),那么所有未被捕获的异常将被ErrorController :: error会捕获你定义的一个。
参数
flag
bool
返回值
例子
示例#1 Yaf_Dispatcher :: catchException()示例
/* 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 errorAction($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;
}
}
}
?>
The above example will output something similar to:
/* 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
扩展内容
- Yaf_Dispatcher :: throwException() - 打开/关闭异常抛出
- Yaf_Dispatcher :: setErrorHandler() - 设置错误处理程序
← Yaf_Dispatcher::autoRender
Yaf_Dispatcher::__clone →