Description
A catch block of a checked exception E may be hidden because the corresponding try block only throws exceptions derived from E and these are handled in catch blocks prior to the catch block of the base exception E. This is essentially dead code and could indicate a bug.
Type
Code Smell
Snippet
public class HiddenCatchBlock {
public static class CustomException extends Exception {
}
public static class CustomDerivedException extends CustomException {
}
public static void main(String[] args) {
try {
throw new CustomDerivedException();
} catch(CustomDerivedException e) {
//...
} catch(CustomException e) { // Noncompliant
//...
}
}
}
Note
Also covered by Eclipse JDT.