Kotlin

Kotlin

Made by DeepSource

Method should not return from finally blocks KT-W1004

Anti-pattern
Major

Avoid returning from within a finally block, as this can prevent normal exception handling control flow from executing.

Reports all return statements in finally blocks. Using return statements in finally blocks can discard and hide exceptions that are thrown in the try block. Furthermore, this rule reports values from finally blocks, if the corresponding try is used as an expression.

Bad Practice

fun foo() {
    try {
        throw MyException()
    } finally {
        return // prevents MyException from being propagated
    }
}

Recommended

Remove return statements from finally blocks.