Java

Java

Made by DeepSource

Empty catch clauses may hide exceptions JAVA-E0052

Anti-pattern
Major

When a catch clause is empty, it essentially ignores any occurrences of the particular exception it handles. This could allow critical bugs to go undiagnosed because any relevant exceptions indicative of a bug would be discarded within this catch block.

Examples

Problematic Code

try {
    // ...
} catch(Exception e) {
    // Nothing here
}

Recommended

Consider at least logging the exception to ensure that issues that may actually be bugs are not missed.

try {
    // ...
} catch(Exception e) {
    System.err.println(e.message); // It may be better to make use of a more robust logging solution like logback.
}

References