A finally block throws, which replaces an exception in flight
What it finds
An exception thrown in finally replaces one thrown in the try, which is then lost along with its stack trace. Cleanup that may fail can catch its own failure, or add it with addSuppressed.
From the rule's source, throw_in_finally.rs.
fun close(stream: java.io.InputStream) { try { stream.read() } finally { if (broken()) throw IllegalStateException("broken")tx0 reports: a throw in finally replaces try { stream.close() } catch (e: java.io.IOException) { log(e) } }} 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:
[rules]
"tx0/kotlin:throw-in-finally" = "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:throw-in-finally] reason="..."tx0 explain tx0/kotlin:throw-in-finally shows the same in the terminal. Found a false positive? Report it.