Kotlin multiplatform project - Checked exception

Hi all,

I am trying to create a kotlin Multiplatform library which can later convert into java and javascript using IDEA 2019.3, kotlin 1.3 .

From the doc, I understood that there is no checked exception in kotlin and for java we can use Throws https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.native/-throws/index.html. In commonMain of multiplatform project, I could not use Throws and I understood the reason behind it. I would like to know how people usually handle Checked exception in commonMain. I am planning to throw an unchecked exception.

Is there a way to convert the ’ unchecked exception’ see as a checked exception in java classes?

Checked exceptions really start going out of control when projects grow. As such, Java devs have stopped using them for real few years ago.

Yes, they still teach you that they are needed and the compiler still errors if do not handle some, but it not that easy to handle errors in reality and other approaches have to be made. Also Kotlin is much less error prone then Java.

As such, JetBrains decided to drop checked exceptions for good for Kotlin. Only Kotlin/JVM has them in the form of annotation just for consistency with the JVM world.

Have a look at this talk from KotlinConf2109 for clarity.

1 Like