Yaf_Request_Abstract::getException
(Since Yaf 1.0.0.12)
public Exception Yaf_Request_Abstract::getException( void );
本方法主要用于在异常捕获模式下, 在异常发生的情况时流程进入Error控制器的error动作时, 获取当前发生的异常对象
例 11.65. Yaf_Request_Abstract::getException 的例子
<?php
class ErrorController extends Yaf_Controller_Abstract {
public funciton errorAction() {
$exception = $this->getRequest()->getException();
}
}
?>
要让本方法能取到异常, 必须先通过Yaf_Dispatcher::catchException开启异常捕获,
这样分发过程中抛出的异常才会被转发到Error控制器的error动作.
框架把捕获到的异常作为名为"exception"的请求参数保存在请求中, 因此在error动作中也可以直接获取它:
通过动作参数获取异常的例子
<?php
class ErrorController extends Yaf_Controller_Abstract {
public function errorAction($exception) {
var_dump($this->getRequest()->getException() === $exception); /* bool(true) */
}
}
?>