Java

Java

Made by DeepSource

Method may ignore exceptions JAVA-S0052

Anti-pattern
Major

This method might ignore an exception. In general, exceptions should be handled, reported in some way, or rethrown by the method.

Not handling exceptions properly may result in bugs that go unnoticed until it is too late.

Examples

Problematic Code

try {
    // ...
} catch (NoSuchElementException e) {
    // ...
} 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 (NoSuchElementException e) {
    // ...
} catch(Exception e) {
    System.err.println(e.message);
}

References