Skip to content

Files

Latest commit

 

History

History
47 lines (38 loc) · 885 Bytes

RethrowCaughtException.md

File metadata and controls

47 lines (38 loc) · 885 Bytes

Pattern: Rethrown exception without modification

Issue: -

Description

Reports all exceptions that are caught and then later re-thrown without modification. It ignores caught exceptions that are rethrown if there is work done before that.

Example of incorrect code:

fun foo() {
    try {
        // ...
    } catch (e: IOException) {
        throw e
    }
}

Example of correct code:

fun foo() {
    try {
        // ...
    } catch (e: IOException) {
        throw MyException(e)
    }
    try {
        // ...
    } catch (e: IOException) {
        print(e)
        throw e
    }
    try {
        // ...
    } catch (e: IOException) {
        print(e.message)
        throw e
    }
}

Further Reading