Inspectopedia Help

Catch block may ignore exception

Reports 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) { }

Locating this inspection

By ID

Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.

CatchMayIgnoreException
Via Settings dialog

Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.

Settings or Preferences | Editor | Inspections | Java | Error handling

Configure the inspection:

  • Use the Do not warn when 'catch' block contains a comment option to ignore catch blocks with comments.

  • Use the Do not warn when 'catch' block is not empty option to ignore catch blocks that contain statements or comments inside, while the variable itself is not used.

  • Use the Do not warn when exception named 'ignore(d)' is not actually ignored option to ignore variables named ignored if they are in use.

New in 2018.1

Inspection options

Here you can find the description of settings available for the Catch block may ignore exception inspection, and the reference of their default values.

Do not warn when 'catch' block contains a comment

Default: Selected

Do not warn when 'catch' block is not empty

Default: Selected

Do not warn when exception named 'ignore(d)' is not actually ignored

Not selected

Availability

By default bundled with

IntelliJ IDEA 2024.1, Qodana for JVM 2024.1,

Can be installed with plugin

Java, 241.18072

Last modified: 18 June 2024