Files
openide/java/java-impl/resources/inspectionDescriptions/TooBroadCatch.html
2025-02-05 04:43:28 +00:00

31 lines
1.1 KiB
HTML

<html>
<body>
Reports <code>catch</code> blocks with parameters that are more generic than the
exception thrown by the corresponding <code>try</code> block.
<p><b>Example:</b></p>
<pre><code>
try {
File file = new File(pathToFile);
return file.getAbsolutePath();
} catch (Exception ex) { // warning: 'catch' of 'Exception' is too broad, masking exceptions 'RuntimeException'
return defaultFilePath;
}
</code></pre>
<p>After the quick-fix is applied:</p>
<pre><code>
try {
File file = new File(pathToFile);
return file.getAbsolutePath();
} catch (RuntimeException ex) {
return defaultFilePath;
}
</code></pre>
<!-- tooltip end -->
<p>Configure the inspection:</p>
<ul>
<li>Use the <b>Only warn on RuntimeException, Exception, Error or Throwable</b> option to have this inspection warn only on the most generic exceptions.</li>
<li>Use the <b>Ignore exceptions which hide others but are themselves thrown</b> option to ignore any exceptions that hide other exceptions but
still may be thrown and thus are technically not overly broad.</li>
</ul>
</body>
</html>