/** * Output an HTML crash report based on an exception. Can use a custom * template stored in 'app/templates/error/exception.php'. * @param \Exception $exception \Exception to report. */ public function crashReport($exception) { $app = $this->name; $version = $this->version; if ($exception instanceof \ErrorException) { $title = tr('Fatal error (%1)', ErrorHandler::toString($exception->getSeverity())); } else { $title = tr('Uncaught exception'); } $log = array(); if ($this->logger instanceof \Jivoo\Core\Log\Logger) { $log = $this->logger->getLog(); } $custom = null; try { if (isset($this->errorPaths['exceptionTemplate'])) { include $this->errorPaths['exceptionTemplate']; $custom = true; } } catch (\Exception $e) { $this->logger->alert(tr('Exception template (%1) failed: %2', '{template}', $e->getMessage()), array('template' => $this->errorPaths['exceptionTemplate'], 'exception' => $e)); } if (!isset($custom)) { include \Jivoo\PATH . '/Core/templates/error/exception.php'; } }
public static function dumpException(\Exception $exception, $stream = STDERR) { if ($exception instanceof \ErrorException) { $title = 'Fatal error (' . ErrorHandler::toString($exception->getSeverity()) . ')'; } else { $title = get_class($exception); } fwrite($stream, $title . ': ' . $exception->getMessage() . ' in ' . $exception->getFile() . ':' . $exception->getLine() . PHP_EOL . PHP_EOL); fwrite($stream, 'Stack trace:' . PHP_EOL); $trace = $exception->getTrace(); foreach ($trace as $i => $call) { $message = ' ' . sprintf('% 2d', $i) . '. '; if (isset($call['file'])) { $message .= $call['file'] . ':'; $message .= $call['line'] . ' '; } if (isset($call['class'])) { $message .= $call['class'] . '::'; } $message .= $call['function'] . '('; $arglist = array(); if (isset($call['args'])) { foreach ($call['args'] as $arg) { $arglist[] = is_scalar($arg) ? var_export($arg, true) : gettype($arg); } $message .= implode(', ', $arglist); } $message .= ')' . PHP_EOL; fwrite($stream, $message); } $previous = $exception->getPrevious(); if (isset($previous)) { fwrite($stream, 'Caused by:' . PHP_EOL); self::dumpException($previous); } fflush($stream); }