Pattern: Unreachable catch block
Issue: -
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()
}
}