Ir al contenido

Catch Without Log Or Rethrow (ARCH7165)

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

Key php.logging.catch-log-only · Severity info · Category logging

Catching and logging an exception then continuing normally without rethrowing can be an unintended swallow for unrecoverable errors.

<?php
try {
$this->chargeCard($order);
} catch (PaymentException $e) {
$this->logger->error('Charge failed', ['exception' => $e]);
// flow continues, order treated as paid
}
<?php
try {
$this->chargeCard($order);
} catch (PaymentException $e) {
$this->logger->error('Charge failed', ['exception' => $e]);
throw $e;
}

Rethrow the exception after logging for unrecoverable errors.