A catch block throws a new exception without the caught one as its cause
What it finds
catch (e: IOException) { throw ConfigException("cannot read") } loses the original exception and its stack trace, which often hold the reason for the failure. Passing e as the cause keeps it. Reported when the caught variable appears nowhere in the thrown expression.
From the rule's source, lost_exception_cause.rs.
fun config(path: String): String { try { return read(path) } catch (e: java.io.IOException) { throw ConfigException("cannot read $path")tx0 reports: the new exception drops the caught e }} fun kept(path: String): String { try { return read(path) } catch (e: java.io.IOException) { throw ConfigException("cannot read $path", 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:lost-exception-cause" = "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:lost-exception-cause] reason="..."tx0 explain tx0/kotlin:lost-exception-cause shows the same in the terminal. Found a false positive? Report it.