Yes. But `kotlin.Throwable` isn’t extending `java....
# stdlib
h
Yes. But
kotlin.Throwable
isn’t extending
java.lang.Throwable
. Also the docs are not too helpful: https://kotlinlang.org/docs/reference/exceptions.html states that
All exception classes in Kotlin are descendants of the class Throwable
but I could not find any example in the stdlib. E.g. see kotlin.KotlinNullPointerException as a counter-example.
i
Descendants doesn't mean direct descendants.
kotlin.Throwable
doesn't have its own runtime representation in JVM and is mapped onto
java.lang.Throwable
in runtime
h
Thanks. So should I then use it as baseclass for my own exception classes instead of jvm exception classes for better crossplatform interop?
i
Do you use java.lang.Throwable as a base class for exceptions in Java? Usually, no — you peek some more specific exception type and extend it.
h
Ok I’ll do so, thanks for your help.
i
If you want your exceptions to be multiplatform you can choose on of exceptions in `kotlin`:
kotlin.Exception
,
kotlin.Error
,
kotlin.RuntimeException
etc. On JVM these are typealiases to JDK exception classes.