Hi all! I have a question regarding
Exceptions in Multiplatform
(for the JVM target).
I have a multiplatform lib with a method that can throw a custom exception. In Java code I’m using that method surrounded with a try/catch. I was expecting that custom exception to arrive but it was not working. I just added another catch with a general
Throwable
exception, now it worked and also what got my attention is that it’s a
RuntimeException
where the
cause
has my CustomException, so I can access it from there but it’s kind of annoying. Does anyone know how to improve this?
So it looks like this:
try {
return mppApi.getSomethingWithExceptionInMultiplatform();
} catch (MyCustomException e) {
// never gets here...
} catch (Throwable e) {
if (e.getCause() instanceof MyCustomException) {
// here I can access my custom exception fields with
// ((MyCustomException) e.getCause())
}
throw e;
}