/** * Default mechanism for handling uncaught exceptions. * Will fetch the current controller instance or instantiate an ErrorController. * The error view template will be rendered. * * @uses Titon\Debug\Debugger * * @param \Exception $exception */ public function handleError(Exception $exception) { if (class_exists('Titon\\Debug\\Debugger')) { Debugger::logException($exception); } // Get the controller try { $controller = Registry::get('titon.controller'); if (!$controller instanceof Controller) { throw new MissingControllerException(); } } catch (Exception $e) { $controller = new ErrorController(); $controller->initialize(); } // And the view try { $view = Registry::get('titon.view'); if (!$view instanceof ViewInterface) { throw new MissingViewException(); } } catch (Exception $e) { $view = new View(); $view->addHelper('html', new HtmlHelper()); $view->addHelper('block', new BlockHelper()); $view->addHelper('asset', new AssetHelper(['webroot' => $this->getWebroot()])); } $controller->setView($view); $controller->setRequest($this->getRequest()); $controller->setResponse($this->getResponse()); $this->emit('mvc.preError', [$this, $controller, $exception]); $response = $controller->renderError($exception); $this->emit('mvc.postError', [$this, $controller, $exception, &$response]); $this->getResponse()->body($response)->respond(); $this->emit('mvc.onShutdown', [$this]); exit; }