KT.THROWING_NEW_INSTANCE_OF_SAME_EXCEPTION
Exception wrapped inside the same exception type and then rethrown
Exceptions should not be wrapped inside the same exception type and then rethrown. Prefer wrapping exceptions in more meaningful exception types.
Noncompliant Code
Copy
fun foo() {
try {
// ...
} catch (e: IllegalStateException) {
throw IllegalStateException(e) // rethrows the same exception
}
}
Compliant Code
Copy
fun foo() {
try {
// ...
} catch (e: IllegalStateException) {
throw MyException(e)
}
}