Skip to content

Files

Latest commit

 

History

History
33 lines (24 loc) · 711 Bytes

TooGenericExceptionThrown.md

File metadata and controls

33 lines (24 loc) · 711 Bytes

Pattern: Too generic thrown exception

Issue: -

Description

Reports thrown exceptions that have a type that is too generic. It should be preferred to throw specific exceptions to the case that has currently occurred.

Example of incorrect code:

fun foo(bar: Int) {
    if (bar < 1) {
        throw Exception() // too generic exception thrown here
    }
    // ...
}

Example of correct code:

fun foo(bar: Int) {
    if (bar < 1) {
        throw IllegalArgumentException("bar must be greater than zero")
    }
    // ...
}

Further Reading