Zum Inhalt springen

Catch Without Log Or Rethrow (ARCH4165)

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

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

Logging an exception and then continuing normally without rethrowing may mean an unrecoverable error is being swallowed unintentionally. The caller never learns that the operation failed.

public void transfer(Account from, Account to, BigDecimal amount) {
try {
ledger.move(from, to, amount);
} catch (LedgerException e) {
log.error("Transfer failed", e);
}
}
public void transfer(Account from, Account to, BigDecimal amount) {
try {
ledger.move(from, to, amount);
} catch (LedgerException e) {
log.error("Transfer failed", e);
throw new TransferException(e);
}
}

Rethrow in addition to logging for unrecoverable errors; if swallowing is intentional, document the reason explicitly.