/** * handle a thrown exception * * @return boolean $use_template */ protected function handleError(\Exception $e) { // canary... /// $this->handleRecursion($e); $event = new InfoEvent('Handling Exception', array('e' => $e)); $this->broadcastEvent($event); // deprecated, this can all be removed when I remove handleRecursion $e_list = $this->getField('e_list', array()); $e_list[] = $e; $this->setField('e_list', $e_list); $ret_mixed = null; if ($e instanceof \Montage\Exception\InternalRedirectException) { $controller_response = $this->handleRequest($e->getPath()); $ret_mixed = $this->handleResponse($controller_response); } else { if ($e instanceof \Montage\Exception\RedirectException) { $response = $this->getContainer()->getResponse(); $redirect_url = $e->getUrl(); $wait_time = $e->getWait(); $response->killTemplate(); $response->setContent(''); $response->setStatusCode($e->getCode()); $response->setHeader('Location', $redirect_url); $controller_response = null; if (headers_sent()) { // http://en.wikipedia.org/wiki/Meta_refresh $response->setContent(sprintf('<meta http-equiv="refresh" content="%s;url=%s">', $wait_time, $redirect_url)); $controller_response = null; } else { if ($wait_time > 0) { sleep($wait_time); } //if $controller_response = false; } //if/else $ret_mixed = $this->handleResponse($controller_response); } else { if ($e instanceof Montage\Exception\StopException) { // don't do anything, we're done $ret_mixed = $this->handleResponse($e->getControllerResponse()); } else { if ($e instanceof \ReflectionException) { $this->handleRecovery($e); // re-handle the request... $ret_mixed = $this->handle(); } else { if ($this->isHandled(self::HANDLE_PRE)) { $event = new FilterEvent('framework.handleError', $e); $event->setField('e_list', $e_list); $this->broadcastEvent($event); $ret_mixed = $this->handleResponse($event->getParam()); // not sure this is best choice, } else { // we can't "gracefully" handle the exception because the framework isn't ready, so just throw // the exception because there is a very high probability it will fail handling // the exception again... throw $e; } //if/else } } } } //if/else return $ret_mixed; }