mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Java: clarify help for java/unreachable-catch-clause
This commit is contained in:
@@ -1,11 +1,10 @@
|
||||
FileInputStream fis = null;
|
||||
FileOutputStream fos = null;
|
||||
try {
|
||||
fis = new FileInputStream(new File("may_not_exist.txt"));
|
||||
// read from input stream
|
||||
fos = new FileOutputStream(new File("may_not_exist.txt"));
|
||||
} catch (FileNotFoundException e) {
|
||||
// ask the user and try again
|
||||
} catch (IOException e) {
|
||||
// more serious, abort
|
||||
} finally {
|
||||
if (fis!=null) { try { fis.close(); } catch (IOException e) { /*ignore*/ } }
|
||||
if (fos!=null) { try { fos.close(); } catch (IOException e) { /*ignore*/ } }
|
||||
}
|
||||
@@ -45,7 +45,13 @@ than one of the <code>catch</code> clauses, only the first matching clause is ex
|
||||
</recommendation>
|
||||
<example>
|
||||
|
||||
<p>In the following example, the second <code>catch</code> clause is unreachable, and can be removed.</p>
|
||||
<p>
|
||||
In the following example, the second <code>catch</code> clause is unreachable.
|
||||
The code is incomplete because a <code>FileOutputStream</code> is opened but
|
||||
no methods are called to write to the stream. Such methods typically throw
|
||||
<code>IOException</code>s, which would make the second <code>catch</code> clause
|
||||
reachable.
|
||||
</p>
|
||||
|
||||
<sample src="PartiallyMaskedCatch.java" />
|
||||
|
||||
|
||||
Reference in New Issue
Block a user