Exceptions, Throwables, Errors, which course to take?

Hello everybody. I'm a bit lost at the moment with `Exception`s in Kotlin and what course to take with a library API. From kotlinlang.org it states that:

All exception classes in Kotlin are descendants of the class Exception.

In the Java landscape we have `Exception` and `Error` and the shared parent `Throwable`. In the JavaScript landscape we have `Error`s. (I know the focus is on 1.0 and Java at the moment). If I want to create a future proof API, so also supporting JavaScript in the future, what approach  should I use to properly facilitate Exception handling?  I now use `Promise<Foo, Exception>` in my API of Kovenant.  But this already leads to usability issues, as pointed out by @jaysonminard, in cases where other (java) libraries/frameworks are used that have`Throwable` in their interface. It seems that not all Throwables are descendants of the class Exception.

I don’t want to change the signature to Promise&lt;Foo, Throwable&gt; as I believe that doesn’t work with javascript implementations, or does it? So will there be (somewhere in the future) some generalized Exception class that plays well with all supported languages or am I overlooking something already?

It's a mistake in the docs. You can use Throwable.

1 Like

Okay thanks, so the intent/implementation is that Throwable maps to JavaScripts Error object?

Update: I see this indeed works perfectly on JavaScript as well.

I think that there is a distinction to be made here when we talk about Java, and I’m posting it on this old thread just to clarify.
You can use Throwable in Kotlin, but you must ask yourself if you should use it.
End-user applications and client code should rarely handle try/catch and error management with Throwable. One of its implementations is the unchecked exception Error; and the documentation for it is very clear:

An Error is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch.

Normal application code should only deal with Exception and its subclasses.