A catch catches Exception or RuntimeException rather than the failures expected
What it finds
catch (e: Exception) handles every failure the same way, including programming errors that should surface. Naming the expected exceptions documents the failure modes and lets the others reach a handler that knows them. Blocks that throw again are left alone.
From the rule's source, catch_generic_exception.rs.
fun run() { try { work() } catch (e: Exception) { log(e) }tx0 reports: catching Exception handles every failure try { work() } catch (e: RuntimeException) { throw IllegalStateException(e) } try { work() } catch (e: java.io.IOException) { log(e) }} Turn it on, off or suppress it
The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/kotlin:catch-generic-exception" = "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-generic-exception] reason="..."tx0 explain tx0/kotlin:catch-generic-exception shows the same in the terminal. Found a false positive? Report it.