Skip to content

Files

Latest commit

 

History

History
42 lines (31 loc) · 652 Bytes

UnreachableCatchBlock.md

File metadata and controls

42 lines (31 loc) · 652 Bytes

Pattern: Unreachable catch block

Issue: -

Description

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

Example of incorrect code:

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

Example of correct code:

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

Further Reading