Why is this thrown exception duplicated?

101 Views Asked by At

This is a follow up question of this question, which is not really important.

I have written the following front controller plugin:

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

Where $monitor is an instance of a custom DB logging class (extending Zend_Log).

In the log method of the Monitor I loop over the Array of Zend_Exceptions returned by $response->getException().

For testing purposes I through an exception in an action:

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

Most things work as expected, the Exception is written to the database.

Question

But, it's written twice. Why?

1

There are 1 best solutions below

0
On BEST ANSWER

Because the dispatch loop is called twice. First for the current action and then for default:error:error :) Place the log into dispatchLoopShutdown() method