Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. StackTraceFormatter.php

function StackTraceFormatter::format

Formats an exception in a java-like format.

Parameters

Throwable $e exception to format:

Return value

string formatted exception

See also

https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/…()

2 calls to StackTraceFormatter::format()
Span::formatStackTrace in vendor/open-telemetry/sdk/Trace/Span.php
Backward compatibility methods
Span::recordException in vendor/open-telemetry/sdk/Trace/Span.php
@inheritDoc

File

vendor/open-telemetry/sdk/Common/Exception/StackTraceFormatter.php, line 37

Class

StackTraceFormatter
@psalm-type Frame = array{ function: string, class: ?class-string, file: ?string, line: ?int, } @psalm-type Frames = non-empty-list<Frame>

Namespace

OpenTelemetry\SDK\Common\Exception

Code

public static function format(Throwable $e) : string {
    $s = '';
    $seen = [];
    
    /** @psalm-var Frames|null $enclosing */
    $enclosing = null;
    do {
        if ($enclosing) {
            self::writeNewline($s);
            $s .= 'Caused by: ';
        }
        if (isset($seen[spl_object_id($e)])) {
            $s .= '[CIRCULAR REFERENCE: ';
            self::writeInlineHeader($s, $e);
            $s .= ']';
            break;
        }
        $seen[spl_object_id($e)] = $e;
        $frames = self::frames($e);
        self::writeInlineHeader($s, $e);
        self::writeFrames($s, $frames, $enclosing);
        $enclosing = $frames;
    } while ($e = $e->getPrevious());
    return $s;
}
RSS feed
Powered by Drupal