Skip to content

Swallowed Exception (ARCH4151)

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.

public User find(String id) {
try {
return repository.load(id);
} catch (SQLException e) {
return null;
}
}
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.