KT.UNREACHABLE_CATCH_BLOCK

Unreachable 'catch' block

Reports unreachable 'catch' blocks. Catch blocks can be unreachable if the exception has already been caught in the block above.

Noncompliant Code

Copy
fun test() {
    try {
        foo()
    } catch (t: Throwable) {
        bar()
    } catch (e: Exception) {
        // Unreachable
        baz()
    }
}

Compliant Code

Copy
fun test() {
    try {
        foo()
    } catch (e: Exception) {
        baz()
    } catch (t: Throwable) {
        bar()
    }
}

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