https://kotlinlang.org logo
Title
b

bbaldino

07/13/2020, 8:25 PM
I just noticed that
shouldThrow<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.
I'm an idiot. Nothing to see here.
My test:
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 expect
🤦 Shit. Ignore me.
😂 2
l

LeoColman

07/13/2020, 9:11 PM
Happens to all of us 😂