Empty catch blocks can hide exceptions
13 for (PrintWriter o : pubServer.noslist) {
14 o.println("<b>" + msg.username + ": </b>" + msg.message + "<br>");
15 }
16 } catch (Exception e) {17 }18 }
19 }
20}
Description
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.
Bad Practice
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
- Spotbugs - DE_MIGHT_IGNORE