Why this matters
Ignoring exceptions by leaving catch blocks empty can suppress important errors, making debugging difficult and potentially leading to unexpected failures.
Ensure that all caught exceptions are either logged or handled properly. Empty catch blocks are not allowed.
Ignoring exceptions by leaving catch blocks empty can suppress important errors, making debugging difficult and potentially leading to unexpected failures.
Side-by-side examples engineers can pattern-match during review.
try {
someMethod();
} catch (Exception e) {
// Do nothing
}try {
someMethod();
} catch (Exception e) {
log.error("Exception occurred", e);
}try {
someMethod();
} catch (Exception e) {
// Do nothing
}try {
someMethod();
} catch (Exception e) {
log.error("Exception occurred", e);
}From the same buckets as this rule.
Check if loops use equality operators (== or !=) in termination conditions. These can lead to infinite loops if the condition is never met exactly. Instead, use relational operators like < or > for safer loop termination.