Ir al contenido

Throw From Finally (ARCH7155)

Esta página aún no está disponible en tu idioma.

Key php.logging.throw-in-finally · Severity error · Category logging

Throwing inside a finally block masks any in-flight exception from the try body, causing the real failure to be lost.

<?php
try {
$this->process($data);
} finally {
if (!$this->stream->close()) {
throw new \RuntimeException('Close failed');
}
}
<?php
try {
$this->process($data);
} finally {
if (!$this->stream->close()) {
$this->logger->warning('Stream close failed');
}
}

Log the error inside finally instead of throwing; let the original exception propagate.