is there some way to deal with the fact that kotli...
# announcements
v
is there some way to deal with the fact that kotlin methods can throw exceptions such as IOException that are “checked” exceptions in java without `throws`in teh signature?
n
what do you mean? exceptions in kotlin are not checked...
v
yeah i know, but if java is calling kotlin code that throws an IOException, then it’s very surprising to the java code that a checked exception is thrown from a method without
throws
in its signature
s
IOException
is a checked exception in Java and there’s nothing stopping you from throwing it in a function in Kotlin and calling that function from Java
d
You can use the
@Throws
annotation to make it so that Java sees the method as "throwing something".
✔️ 1
👆 1
v
@diesieben07 thanks that’s helpful
n
if java is calling kotlin code that throws an IOException, then it’s very surprising to the java code that a checked exception is thrown from a method without
throws
in its signature
i think the java runtime doesn’t give a damn the java compiler is the one which cares about that
4
s
better yet. if it is completely expected for the method to throw, have it return a Try<T> or a result type, or sealed class etc.
then you dont have to worry from java callsite, because they are forced to see what actually happened. without all of the issues that come with programming with exceptions
h
i think the java runtime doesn’t give a damn the java compiler is the one which cares about that
... and maybe the java developer. ..
👍 1