Well, it doesn't really matter in Kotlin (unless you have a catch-Block for explicitly for RuntimeException of course), but the error you get is thrown by Java code. If your Kotlin exception ends up in some Java code, it can make a difference.
So if you're wprking with Kotlin exceptions in combination with Java code or libs, it's a good idea to either us RuntimeExceptions or
@Throws(MyException::class)
as suggested by @Vampire (equivalent of adding
throws MyException
to the end of a method signature in Java)
s
spand
12/07/2020, 9:18 AM
Since Kotlin mirrors the Java exception hierarchy I would say you should do the same as you would in Java.
t
Tobias Berger
12/07/2020, 9:24 AM
Kotlin doesn't differentiate between checked and unchecked exceptions, so unless you have Java inter-op there is no need to use RuntimeException