Catch Without Log Or Rethrow (ARCH2165)
Esta página aún no está disponible en tu idioma.
Key python.logging.catch-log-only · Severity info · Category logging
Handlers that catch and log an exception then continue normally without rethrowing may hide unrecoverable errors. Even though it is logged, execution proceeds as if the failure never happened.
Incorrect
Section titled “Incorrect”def transfer(amount): try: bank.debit(amount) except BankError: logger.error("Debit failed") bank.credit(amount)Correct
Section titled “Correct”def transfer(amount): try: bank.debit(amount) except BankError: logger.exception("Debit failed") raise bank.credit(amount)Do not log-and-swallow unrecoverable errors; log them and re-raise.