A catch clause only rethrows the exception it caught
What it finds
catch (IOException e) { throw e; } does nothing that leaving the clause out would not: the exception goes on as it came.
Only the last catch clause of a try statement is reported, and only when every clause before it rethrows too: before a later clause, rethrowing keeps that clause from catching the exception, which can be the point.
From the rule's source, catch_rethrow.rs.
import java.io.IOException; class Store { void save() throws IOException { try { write(); } catch (IOException e) { throw e; }tx0 reports: only rethrows the exception try { write(); } catch (java.io.FileNotFoundException e) { throw e; } catch (IOException e) { log(e); } try { write(); } catch (IOException e) { log(e); throw e; } } void write() throws IOException {} void log(Exception e) {}} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/java:catch-rethrow" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/java:catch-rethrow] reason="..."tx0 explain tx0/java:catch-rethrow shows the same in the terminal. Found a false positive? Report it.