Pattern: Use of type check for exception
Issue: -
Instead of catching generic exception types and then checking for specific exception types the code should use multiple catch blocks. These catch blocks should then catch the specific exceptions.
Example of incorrect code:
fun foo() {
try {
// ... do some I/O
} catch(e: IOException) {
if (e is MyException || (e as MyException) != null) { }
}
}
Example of correct code:
fun foo() {
try {
// ... do some I/O
} catch(e: MyException) {
} catch(e: IOException) {
}