@Throws(RuntimeException::class)
fun boom() {
throw RuntimeException("Boom!")
}
fun main() {
val x = 1f
val y = when {
x < 10 -> {
if (x % 2 == 0f) {
boom()
} else {
2f
}
}
x >= 10 -> {
3f
}
else -> {
4f
}
}
println(y.toInt())
}
Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: public inline fun String.toInt(): Int defined in kotlin.text public inline fun String.toInt(radix: Int): Int defined in kotlin.text private fun Iterable<FlagEnum>.toInt(): Int defined in kotlin.text
The Throws annotation is there for interop with java’s checked exception system. This explained in the docs.
While I don’t mind explaining stuff you might want to take a look through the reference part of the kotlin docs: https://kotlinlang.org/docs/reference/
It’s a good place to start looking whenever you have problems with basic language constructs. Still, if you can’t find an answer there feel free to ask