While unreachable catch sections are normally disallowed by Java compiler and reported as compilation errors, the analysis mandated by the Java language is not complete for some cases. This inspection provides enhanced analysis and reports some unreachable catch sections which are not reported by the compiler. Such sections are redundant and could be safely removed.
Example:
void method() {
try {
throw new FileNotFoundException();
}
catch (FileNotFoundException e) {
}
catch (IOException e) {
// this catch is allowed by specification
// but never executed
}
}
The quick-fix is provided, which removes the redundant catch section:
void method() {
try {
throw new FileNotFoundException();
}
catch (FileNotFoundException e) {
}
}
New in 2025.1