bbaldino
07/13/2020, 8:25 PMshouldThrow<SomeException>
won't match if a sub-type of SomeException
is thrown. But when I try and test with code equivalent(?) to what's in shouldThrow
, it does match.sealed class MyException : Exception() {
sealed class SubException : MyException() {
class SubSubException : SubException()
}
}
inline fun <reified T : Throwable> baz() {
try {
throw MyException.SubException.SubSubException()
} catch (t: Throwable) {
when (t) {
is T -> {
println("my exception thrown!")
}
else -> {
println("don't recognize it!")
}
}
}
}
This prints my exception thrown!
as I'd expectLeoColman
07/13/2020, 9:11 PM