Swallowed Exception (ARCH4151)
Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.
Key java.logging.swallowed-exception · Severity error · Category logging
Catching an exception and silently discarding it by returning null/a default differs from an empty catch block but is equally dangerous. The caller never learns about the error and silent data loss can occur.
Incorrect
Section titled “Incorrect”public User find(String id) { try { return repository.load(id); } catch (SQLException e) { return null; }}Correct
Section titled “Correct”public User find(String id) { try { return repository.load(id); } catch (SQLException e) { log.error("Failed to load user: {}", id, e); throw new DataAccessException(e); }}Log and rethrow instead of swallowing; if you must return a default, document the reason explicitly.