Zum Inhalt springen

Rethrow Loses Stack Trace (ARCH7154)

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

Key php.logging.rethrow-without-previous · Severity warning · Category logging

Throwing a new exception inside a handler without passing the original as the previous argument destroys the root cause and stack trace.

<?php
try {
$this->client->request($url);
} catch (TransportException $e) {
throw new ServiceException('Upstream call failed');
}
<?php
try {
$this->client->request($url);
} catch (TransportException $e) {
throw new ServiceException('Upstream call failed', 0, $e);
}

Pass the original exception as the previous (third) argument when throwing the new one.