In future, could Kotlin have checked exception?

First, I love the fact that checked exceptions are missing.
I do use the functional way, though: the Try-class.

The Try-class with getValueUnsafe is the same as unchecked exceptions.
If you don’t have that function, you do need to check the type -> checked exception.

Try-classes with all their callbacks are harder to chain.
But I believe something like that can be solved the same way suspend already solves multithreading.

try fun foo() : String = ""
fun outside() = when(val v = foo()){
    is Success -> println(v.value)
    is Failure -> println(v.failure.message)
}

try fun inside(){
     val value = try { foo() } catch(e : Exception) { it.message }
     println(value)
}

or if you want to simple rethrow on exception:

try fun inside() = println(foo())

Here you tell people clearly that you expect some exception to be thrown.
The drawback:

  • Silencing can easily be done by adding tthe getValue or adding try before the function.
    This way, either lots of functions would become try-functions, or a lot of functions are silenced.
  • Also, it doesn’t tell which exceptions can be thrown.

If a (way better) function like this would be implemented, it would be done in arrow-kt, combined with arrow-meta.

Yes, your idea using “try” functions could/will solve the compatibility to Java, something like I mentioned here.

Maybe ask in the arrow-group on slack if they have ideas how you can implement it using arrow-meta?