huehnerlady
08/19/2020, 8:05 AMI have the following sample function:
fun test(){
val testString: String? = null
testString ?: throw IllegalArgumentException("null")
print(testString.length)
}
I now want to extract the exception throwing to make clear why I do this:
fun test2(){
val testString: String? = null
testString ?: handleUnexpectedNull()
print(testString.length)
}
private fun handleUnexpectedNull() {
throw IllegalArgumentException("null")
}
But here I get a compile error (see screenshot).
Why is this happening and can I extract the exception in a way that still supports smartcast?
I am using the jvm compiling and kotlin 1.3.72gildor
08/19/2020, 8:21 AMgildor
08/19/2020, 8:22 AMgildor
08/19/2020, 8:22 AMhuehnerlady
08/19/2020, 9:04 AMgildor
08/19/2020, 9:04 AMerror()
it’s the same case