catch
blocks that are empty or may ignore an exception.
While occasionally intended, empty catch
blocks may complicate debugging.
Also, ignoring a catch
parameter might be wrong.
Finally, the static code analyzer reports if it detects that a catch
block may silently ignore important VM
exceptions like NullPointerException
. Ignoring such an exception
(without logging or rethrowing it) may hide a bug.
The inspection won't report any catch
parameters named ignore
or ignored
.
Conversely, the inspection will warn you about any catch
parameters named ignore
or ignored
that are actually in use.
Additionally, the inspection won't report catch
parameters inside test sources named expected
or ok
.
You can use a quick-fix to change the exception name to ignored
.
For empty catch blocks, an additional quick-fix to generate the catch body is suggested.
You can modify the "Catch Statement Body" template on the Code tab in
Settings | Editor | File and Code Templates.
Example:
try {
throwingMethod();
} catch (IOException ex) {
}
After the quick-fix is applied:
try {
System.out.println(System.in.read());
} catch (IOException ignored) {
}
Configure the inspection:
catch
blocks with comments.
catch
blocks that contain
statements or comments inside, while the variable itself is not used.
ignored
if they are in use.
New in 2018.1