Rule Definition
When a method is declared to throw an exception but does not throw any exception:
- the caller must write extra code to handle this potential exception
- it makes the code difficult to read
- the caller will have to write a try/catch block that will affect the performance of the application
Remediation
Remove the throw declaration in the signature.
Violation Code Sample
public void aMethod() throws myException {
System.println("a Method"); // VIOLATION
}
Fixed Code Sample
public void aMethod() {
System.println("a Method"); // FIXED
}
Reference
http://www.onjava.com/pub/a/onjava/2003/11/19/exceptions.html
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.