Skip to content

Files

Latest commit

 

History

History
31 lines (22 loc) · 694 Bytes

TooGenericExceptionCaught.md

File metadata and controls

31 lines (22 loc) · 694 Bytes

Pattern: Too generic caught exception

Issue: -

Description

It should be preferred to catch specific exceptions to the case that is currently handled. If the scope of the caught exception is too broad it can lead to unintended exceptions being caught.

Example of incorrect code:

fun foo() {
    try {
        // ... do some I/O
    } catch(e: Exception) { } // too generic exception caught here
}

Example of correct code:

fun foo() {
    try {
        // ... do some I/O
    } catch(e: IOException) { }
}

Further Reading