Rule Definition
Assertion in a catch block has no meaning. It is often related poor conception because:
- assertions are not enabled in production environments, so the application will end-up with an empty catch-block
- assertions do not give any meaning to the issue
Also, in a catch block it is too late to refer to an assertion.
Remediation
The exception must be handled correctly according to its type.
Violation Code Sample
try {
Date defaultDate=format.parse(DEFAULT_DATE_STRING);
...
} catch( ParseException pexc ) {
// This must never happen!
assert false : "bad init value"; // VIOLATION
}
Fixed Code Sample
try {
Date defaultDate=format.parse(DEFAULT_DATE_STRING);
...
} catch( ParseException pexc ) {
// This must never happen!
throw myException("bad init value", pexc); // FIXED
}
Reference
http://www.old.netobjectdays.org/pdf/02/papers/industry/1430.pdf
Related Technologies
JEE
Technical Criterion
Programming Practices - Error and Exception Handling
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.