Phalcon\Utils\PrettyExceptions::handleError PHP Метод

handleError() публичный Метод

Handles errors/warnings/notices
public handleError ( integer $errorCode, string $errorMessage, string $errorFile, integer $errorLine, Phalcon\Mvc\Application $application = null )
$errorCode integer
$errorMessage string
$errorFile string
$errorLine integer
$application Phalcon\Mvc\Application OPTIONAL To display a dump of the current state of the Phalcon application instance.
    public function handleError($errorCode, $errorMessage, $errorFile, $errorLine, $application = null)
    {
        if (ob_get_level() > 0) {
            ob_end_clean();
        }
        if (self::$_showActive) {
            echo $errorMessage;
            return false;
        }
        if (!(error_reporting() & $errorCode)) {
            return false;
        }
        self::$_showActive = true;
        header("Content-type: text/html");
        echo '<html><head><title>Exception - ', $errorMessage, '</title>', $this->getCssSources(), '</head><body>';
        echo '<div class="error-main">
			', $errorMessage, '
			<br/><span class="error-file">', $errorFile, ' (', $errorLine, ')</span>
		</div>';
        if ($this->_showBackTrace) {
            echo '<div class="error-backtrace"><table cellspacing="0">';
            foreach (debug_backtrace() as $n => $trace) {
                if ($n == 0) {
                    continue;
                }
                $this->_showTraceItem($n, $trace);
            }
            echo '</table></div>';
        }
        $this->showApplicationDump($application);
        echo $this->getVersion();
        echo $this->getJsSources() . '</body></html>';
        self::$_showActive = false;
        return true;
    }

Usage Example

 /**
  * @param      $exceptionOrCode
  * @param null $message
  * @param null $file
  * @param null $line
  *
  * @return bool
  */
 protected function getTemplate($exceptionOrCode, $message = NULL, $file = NULL, $line = NULL)
 {
     if ($exceptionOrCode instanceof \Exception) {
         $message = $exceptionOrCode->getMessage();
         $file = $exceptionOrCode->getFile();
         $line = $exceptionOrCode->getLine();
     }
     $prettyPrinter = new PrettyExceptions();
     $prettyPrinter->showFiles(TRUE);
     $prettyPrinter->showFileFragment(TRUE);
     $prettyPrinter->setTheme('night');
     ob_start();
     ob_start();
     $prettyPrinter->handleError(-1, $message, $file, $line);
     return $this->handleTemplate();
 }