Reputation: 33
I am using SonarQube for my code quality analysis. I am coding in java with the use of AbstractJavaSequence
from AdroidLogic API.
Many of my project classes extend this class and override execute method which by default declare throws Exception
. The SonarQube analysis raises an issue, stating that the class uses a generic exception instead of specific one.
How can I resolve this SonarQube issue?
Upvotes: 2
Views: 706
Reputation: 8331
Just because the method you are overriding throws Exception
, it doesn't mean you have to.
You are free to not declare that you throw any exceptions at all, or to throw specific exceptions instead:
public abstract class ParentClass {
abstract void doSomething() throws Exception;
}
These are all valid (obviously, not all at once):
public class ChildClass extends ParentClass {
public void doSomething() {
}
public void doSomething() throws MyException {
}
public void doSomething() throws Exception {
}
}
There's no reason for you to carry on their bad practices.
Upvotes: 2