A catch clause follows one for a supertype of its exception, so it never runs

tx0/kotlin:catch-after-broader-catchdefaultwarningreliability/error-handlingdepth fastbug

What it finds

Catch clauses are tried in order. After catch (e: Exception), a catch (e: IOException) is never reached, since the first clause already took every exception. Reported for the exception classes of the Kotlin and Java standard libraries whose hierarchy is known.

From the rule's source, catch_after_supertype.rs.

Example from the rule's tests
fun load() {    try {        read()    } catch (e: Exception) {        log(e)    } catch (e: java.io.IOException) {tx0 reports: IOException is caught by the earlier catch for Exception        retry()    }    try {        read()    } catch (e: java.io.IOException) {        retry()    } catch (e: Exception) {        log(e)    }    try {        read()    } catch (e: IllegalArgumentException) {        log(e)    } catch (e: NumberFormatException) {tx0 reports: NumberFormatException is caught by the earlier catch for IllegalArgumentException        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 in every tier. To turn it off for a project, set its level in tx0.toml:

tx0.toml
[rules]
"tx0/kotlin:catch-after-broader-catch" = "off"

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-after-broader-catch] reason="..."

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