Skip to content Skip to sidebar Skip to footer

Use Case For Runtimeexception From Package Kotlin

I was writing some code and was going to throw a RuntimeException as a default for something, when I noticed that there are two options for RuntimeException - one from java.lang an

Solution 1:

When using the JDK, these map to JDK classes. When using Kotlin for Javascript, they would map to a specific implementation in the Kotlin Javascript library. Documentation about actual and expecthere.

To answer your question, if there's a chance of you porting your code to also work on another platform, always use the kotlin. variant. Otherwise, it doesn't matter.

Solution 2:

In my opinion typealias is strong feature provided by Kotlin language.

Why? Because it gives ability to extend code to multiple domains like extension to provide interoperability between any other languages and Kotlin.

It also becomes helpful when providing APIs or SDK with semantic versioning without worrying much about changes affecting on lower versions of APIs.

One good example would be Collections derived from Java to Kotlin language with some additional & powerful methods as typealias (Literally it saves lot of development time and efforts).

Another good example would be multiplatform programming support by Kotlin language that helps you create APIs with actual and expect keywords implementation.

So long story short, I prefer using RuntimeException from Kotlin package to extend support amongst variety of Kotlin versions (You can see newly added classes starting from version 1.3, but doesn't affect existing API).

Post a Comment for "Use Case For Runtimeexception From Package Kotlin"