is
or as
KT-W1000Avoid using is
to check the type of exceptions, or as
to cast exception types within catch blocks.
This issue is reported when a catch block uses a type check, or attempts to cast the caught exception to a specific type. 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.
fun foo() {
try {
// ... do some I/O
} catch(e: IOException) {
if (e is MyException || (e as MyException) != null) { }
}
}
Make sure there is only one @Inject
constructor in every class.
fun foo() {
try {
// ... do some I/O
} catch(e: MyException) {
} catch(e: IOException) {
}
}