Exception, RuntimeException, Throwable or Error is thrown, which callers cannot tell apart
What it finds
throw Exception("not found") forces callers that want to handle this case to catch every exception. A specific type, from the standard library such as IllegalArgumentException or IllegalStateException, or an own one, lets them handle exactly it. require, check and error throw the usual ones.
From the rule's source, generic_exception_thrown.rs.
fun find(id: Int): String { if (id < 0) throw Exception("negative")tx0 reports: throwing Exception leaves callers if (id == 0) throw RuntimeException()tx0 reports: throwing RuntimeException if (id > 9) throw IllegalArgumentException("too big") return "x"} 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:unspecific-exception-raised" = "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:unspecific-exception-raised] reason="..."tx0 explain tx0/kotlin:unspecific-exception-raised shows the same in the terminal. Found a false positive? Report it.