https://kotlinlang.org logo
Title
h

holgerbrandl

04/04/2018, 2:49 PM
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

ilya.gorbunov

04/04/2018, 3:02 PM
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

holgerbrandl

04/04/2018, 3:04 PM
Thanks. So should I then use it as baseclass for my own exception classes instead of jvm exception classes for better crossplatform interop?
i

ilya.gorbunov

04/04/2018, 3:06 PM
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

holgerbrandl

04/04/2018, 3:07 PM
Ok I’ll do so, thanks for your help.
i

ilya.gorbunov

04/04/2018, 3:09 PM
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.