本文整理汇总了PHP中Throwable::getPrevious方法的典型用法代码示例。如果您正苦于以下问题:PHP Throwable::getPrevious方法的具体用法?PHP Throwable::getPrevious怎么用?PHP Throwable::getPrevious使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Throwable
的用法示例。
在下文中一共展示了Throwable::getPrevious方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getPreviousExceptionInspector
/**
* Returns an Inspector for a previous Exception, if any.
* @todo Clean this up a bit, cache stuff a bit better.
* @return Inspector
*/
public function getPreviousExceptionInspector()
{
if ($this->previousExceptionInspector === null) {
$previousException = $this->exception->getPrevious();
if ($previousException) {
$this->previousExceptionInspector = new Inspector($previousException);
}
}
return $this->previousExceptionInspector;
}
示例2: dispatchException
/**
* Send exception message to client
* @param \Exception $exception
*/
public function dispatchException(\Throwable $exception)
{
if ($this->isActive()) {
if ($this->dispatchPreviousExceptions && $exception->getPrevious()) {
$this->dispatchException($exception->getPrevious());
}
$message = new \PhpConsole\ErrorMessage();
$message->code = $exception->getCode();
$message->class = get_class($exception);
$message->data = $this->dumper->dump($exception->getMessage());
$message->file = $exception->getFile();
$message->line = $exception->getLine();
$message->trace = self::fetchTrace($exception->getTrace(), $message->file, $message->line);
$this->sendMessage($message);
}
}
示例3: handle_exception
/**
* @param \Exception|\Throwable $exception
*/
public function handle_exception($exception)
{
if (getenv('APP_ENV') === 'dev') {
list($code, $file, $line, $message, $previous, $trace, $trace_string) = [$exception->getCode(), $exception->getFile(), $exception->getLine(), $exception->getMessage(), $exception->getPrevious(), $exception->getTrace(), $exception->getTraceAsString()];
$trace_info = "<b>file</b>: {$trace[0]['file']} <b>in line</b> ({$trace[0]['line']})";
echo "<h2>COGS Runtime Exception: [::{$code}] {$message}</h2>";
echo "<b>Trace:</b><br>";
echo "<pre>{$trace_string}</pre>";
echo "<b>Debug:</b><br>";
dump(compact('code', 'file', 'line', 'message', 'previous', 'trace'));
}
}
示例4: handle
/**
* @param Throwable $exception
*/
public function handle(\Throwable $exception)
{
if ($exception instanceof HttpException) {
http_response_code($exception->getStatusCode());
}
if (false === $this->debug) {
return;
}
if (null !== $exception->getPrevious()) {
$exception = $exception->getPrevious();
}
$message = $exception->getMessage();
$trace = $exception->getTrace();
array_unshift($trace, array('function' => '', 'file' => $exception->getFile() != null ? $exception->getFile() : null, 'line' => $exception->getLine() != null ? $exception->getLine() : null, 'args' => array()));
$firstTrace = array_shift($trace);
$firstTrace['excerpt'] = $this->excerpt($firstTrace['file'], $firstTrace['line']);
array_unshift($trace, $firstTrace);
echo $this->templateEngine->render(__DIR__ . '/templates/exception.php', array('message' => $message, 'trace' => $trace));
}
示例5: resolveException
/**
* @deprecated
* @internal
* @param \Exception|\Throwable $e
* @param string $query
* @param array $params
* @return DBALException
*/
public function resolveException($e, $query = NULL, $params = [])
{
if ($this->throwOldKdybyExceptions !== TRUE) {
return $e;
}
if ($e instanceof Doctrine\DBAL\DBALException && ($pe = $e->getPrevious()) instanceof \PDOException) {
$info = $pe->errorInfo;
} elseif ($e instanceof \PDOException) {
$info = $e->errorInfo;
} else {
return new DBALException($e, $query, $params, $this);
}
if ($this->getDriver() instanceof Doctrine\DBAL\Driver\PDOMySql\Driver) {
if ($info[0] == 23000 && $info[1] == self::MYSQL_ERR_UNIQUE) {
// unique fail
$columns = [];
try {
if (preg_match('~Duplicate entry .*? for key \'([^\']+)\'~', $info[2], $m) && ($table = self::resolveExceptionTable($e)) && ($indexes = $this->getSchemaManager()->listTableIndexes($table)) && isset($indexes[$m[1]])) {
$columns[$m[1]] = $indexes[$m[1]]->getColumns();
}
} catch (\Exception $e) {
}
return new DuplicateEntryException($e, $columns, $query, $params, $this);
} elseif ($info[0] == 23000 && $info[1] == self::MYSQL_ERR_NOT_NULL) {
// notnull fail
$column = NULL;
if (preg_match('~Column \'([^\']+)\'~', $info[2], $m)) {
$column = $m[1];
}
return new EmptyValueException($e, $column, $query, $params, $this);
}
}
$raw = $e;
do {
$raw = $raw->getPrevious();
} while ($raw && !$raw instanceof \PDOException);
return new DBALException($e, $query, $params, $this, $raw ? $raw->getMessage() : $e->getMessage());
}
示例6: throwableToArray
/**
* Convert an Exception or Error into an array (for logging)
*
* @param \Throwable $ex
* @return array
*/
function throwableToArray(\Throwable $ex) : array
{
$prev = $ex->getPrevious();
return ['line' => $ex->getLine(), 'file' => $ex->getFile(), 'message' => $ex->getMessage(), 'code' => $ex->getCode(), 'trace' => $ex->getTrace(), 'previous' => $prev ? throwableToArray($prev) : null];
}
示例7: normalizeException
protected function normalizeException(\Throwable $e, int $depth = 0) : string
{
$previousText = '';
if ($previous = $e->getPrevious()) {
do {
$previousText .= ', ' . get_class($previous) . '(code: ' . $previous->getCode() . '): ' . $previous->getMessage() . ' at ' . $previous->getFile() . ':' . $previous->getLine();
} while ($previous = $previous->getPrevious());
}
$str = '[object] (' . get_class($e) . '(code: ' . $e->getCode() . '): ' . $e->getMessage() . ' at ' . $e->getFile() . ':' . $e->getLine() . $previousText . ')';
if ($this->includeStacktraces) {
$str .= "\n[stacktrace]\n" . $e->getTraceAsString() . "\n";
}
return $str;
}
示例8: echoPreviousExceptions
/**
* Echoes previous exceptions if applicable
*
* @author Art <a.molcanovas@gmail.com>
*
* @param null|\Throwable $e The previous exception
* @param int $level How many previous exceptions have been echoed so far
*
* @codeCoverageIgnore
*/
protected function echoPreviousExceptions($e, $level = 0)
{
if ($level < $this->config->prevExceptionDepth && $e) {
if ($this->isCLI) {
$this->console->write('<eb>Preceded by </>')->write('<e>[' . $e->getCode() . '] ' . $e->getMessage() . '</>')->write('<e> @ ' . $e->getFile() . '\'s line ' . $e->getLine() . '</>', true)->writeln('');
} else {
?>
<div>
<span class="alo-bold">Preceded by </span>
<span>[<?php
echo $e->getCode();
?>
]: <?php
echo $e->getMessage();
?>
</span>
<span> @ </span>
<span class="alo-uline"><?php
echo $e->getFile();
?>
</span>
<span> @ line </span>
<span class="alo-uline"><?php
echo $e->getLine();
?>
</div>
<?php
}
$this->echoPreviousExceptions($e->getPrevious(), ++$level);
}
}