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.


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.