A catch clause only rethrows the exception it caught

tx0/java:catch-rethrowrecommendedwarningsmell

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.

Example from the rule's tests
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) {}}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

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:

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.