【问题标题】:Why is this thrown exception duplicated?为什么这个抛出的异常会重复?
【发布时间】:2011-07-19 04:02:09
【问题描述】:

这是this question的后续问题,并不重要。

我写了以下前端控制器插件:

public function postDispatch(Zend_Controller_Request_Abstract $request)
{
    $response = $this->getResponse();
    $monitor = Zend_Registry::get('monitor');
    
    if ($response->isException())
    {
        $monitor->log($response);
    }
}

其中 $monitor 是自定义 DB 日志记录类的一个实例(扩展 Zend_Log)。

在 Monitor 的 log 方法中,我遍历 $response->getException() 返回的 Zend_Exceptions 数组。

出于测试目的,我通过一个动作中的异常:

throw new Zend_Exception('the big test', 555);

大多数事情都按预期工作,异常被写入数据库。

问题

但是,它写了两次。为什么?

【问题讨论】:

    标签: php zend-framework exception-handling zend-controller-plugin


    【解决方案1】:

    因为调度循环被调用了两次。首先是当前操作,然后是 default:error:error :) 将日志放入 dispatchLoopShutdown() 方法

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-24
      • 2010-11-06
      • 2015-05-23
      • 1970-01-01
      相关资源
      最近更新 更多