A catch block only throws the caught exception again

tx0/kotlin:catch-that-only-rethrowsrecommendedwarningreliability/error-handlingdepth fastsmell

What it finds

catch (e: IOException) { throw e } does what having no catch does. It is noise, or a sign that handling was meant to be added. A rethrowing clause followed by a clause for a wider type is left alone, since it keeps the exception from that clause.

From the rule's source, rethrow_only_catch.rs.

Example from the rule's tests
fun read() {    try {        load()    } catch (e: java.io.IOException) {tx0 reports: the catch only throws the exception again        throw e    }    try {        load()    } catch (e: java.io.FileNotFoundException) {        throw e    } catch (e: java.io.IOException) {        log(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/kotlin:catch-that-only-rethrows" = "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/kotlin:catch-that-only-rethrows] reason="..."

tx0 explain tx0/kotlin:catch-that-only-rethrows shows the same in the terminal. Found a false positive? Report it.