本文整理汇总了PHP中RuntimeException::getPrevious方法的典型用法代码示例。如果您正苦于以下问题:PHP RuntimeException::getPrevious方法的具体用法?PHP RuntimeException::getPrevious怎么用?PHP RuntimeException::getPrevious使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RuntimeException
的用法示例。
在下文中一共展示了RuntimeException::getPrevious方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testDefFormatWithPreviousException
public function testDefFormatWithPreviousException()
{
$formatter = new JsonFormatter();
$exception = new \RuntimeException('Foo', 0, new \LogicException('Wut?'));
$formattedPrevException = $this->formatException($exception->getPrevious());
$formattedException = $this->formatException($exception, $formattedPrevException);
$message = $this->formatRecordWithExceptionInContext($formatter, $exception);
$this->assertContextContainsFormattedException($formattedException, $message);
}
示例2: testDefFormatWithPreviousException
public function testDefFormatWithPreviousException()
{
$formatter = new JsonFormatter();
$exception = new \RuntimeException('Foo', 0, new \LogicException('Wut?'));
$message = $formatter->format(array('level_name' => 'CRITICAL', 'channel' => 'core', 'context' => array('exception' => $exception), 'datetime' => new \DateTime(), 'extra' => array(), 'message' => 'foobar'));
if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
$pathPrevious = substr(json_encode($exception->getPrevious()->getFile(), JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), 1, -1);
$pathException = substr(json_encode($exception->getFile(), JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), 1, -1);
} else {
$pathPrevious = substr(json_encode($exception->getPrevious()->getFile()), 1, -1);
$pathException = substr(json_encode($exception->getFile()), 1, -1);
}
$this->assertEquals('{"level_name":"CRITICAL","channel":"core","context":{"exception":{"class":"RuntimeException","message":"' . $exception->getMessage() . '","code":' . $exception->getCode() . ',"file":"' . $pathException . ':' . $exception->getLine() . '","previous":{"class":"LogicException","message":"' . $exception->getPrevious()->getMessage() . '","code":' . $exception->getPrevious()->getCode() . ',"file":"' . $pathPrevious . ':' . $exception->getPrevious()->getLine() . '"}}},"datetime":' . json_encode(new \DateTime()) . ',"extra":[],"message":"foobar"}' . "\n", $message);
}
示例3: logException
public static function logException($exception)
{
if (is_string($exception)) {
$exception = new \RuntimeException($exception);
}
if (self::$error === true || !self::$currentRootSpan || !$exception instanceof \Exception) {
return;
}
// We are only interested in the original exception
while ($previous = $exception->getPrevious()) {
$exception = $previous;
}
self::$error = true;
self::$currentRootSpan->annotate(array("err_msg" => $exception->getMessage(), "err_source" => $exception->getFile() . ':' . $exception->getLine(), "err_exception" => get_class($exception), "err_trace" => \Tideways\Profiler\BacktraceConverter::convertToString($exception->getTrace())));
}