Esempio n. 1
0
 /**
  * 
  * handleException catches Exceptions and displays an error page with the details.
  * @todo create and implement and error controller that can display custom errors
  * per application.
  * @param Exception $ex
  */
 public function handleException(Exception $ex)
 {
     //handle the error
     $this->setLastException($ex);
     //Notify observers
     $this->notify();
     //Clear the output buffer
     ob_clean();
     //Get the Front Controller
     $main = Staple_Main::get();
     //Process the Header
     $main->processHeader(true);
     //Echo the error message
     echo "<div class=\"section\"><div class=\"row\"><div class=\"small-12 columns\"><h1><i class=\"fi-alert\"></i> " . $ex->getMessage() . " Code: " . $ex->getCode() . "</h1></div></div></div>";
     //Echo details if in dev mode
     if ($main->inDevMode()) {
         if (($p = $ex->getPrevious()) instanceof Exception) {
             echo "<p><b>Previous Error:</b> " . $p->getMessage . " Code: " . $p->getCode() . "</p>";
         }
         echo "<pre>" . $ex->getTraceAsString() . "</pre>";
         foreach ($ex->getTrace() as $traceln) {
             echo "<pre>";
             var_dump($traceln);
             echo "</pre>";
         }
     }
     //If the site uses layout, build the default layout and put the error message inside.
     if (Staple_Layout::layoutExists(Staple_Config::getValue('layout', 'default'))) {
         //Grab the current buffer contents to add to the layout
         $buffer = ob_get_contents();
         ob_clean();
         //Create the layout object and build the layout
         $layout = new Staple_Layout(Staple_Config::getValue('layout', 'default'));
         $layout->build($buffer);
     }
 }