Zum Inhalt springen

Catch Without Log Or Rethrow (ARCH2165)

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

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.

def transfer(amount):
try:
bank.debit(amount)
except BankError:
logger.error("Debit failed")
bank.credit(amount)
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.