Avoid throwing a caught exception without modifying it.
This rule reports all exceptions that are caught and then later re-thrown without modification. It ignores cases: 1. When caught exceptions that are rethrown if there is work done before that. 2. When there are more than one catch in try block and at least one of them has some work.
fun foo() {
try {
// ...
} catch (e: IOException) {
throw e
}
}
Ideally, don't rethrow caught exceptions. But if you have to, try to do something with the exception before rethrowing them.
fun foo() {
try {
// ...
} catch (e: IOException) {
// Wrapping the exception to a more specific one.
throw MyException(e)
}
}