KT.THROWING_EXCEPTION_FROM_FINALLY

Exception thrown from a finally block

This rule reports all cases where exceptions are thrown from a finally block. Throwing exceptions from a finally block should be avoided as it can lead to confusion and discarded exceptions.

Noncompliant Code

Copy
fun foo() {
    try {
        // ...
    } finally {
        throw IOException()
    }
}

The content on this page is adapted from the Detekt Docs. Copyright ©2022 The Detekt Team. All rights reserved. https://detekt.dev/comments.html