juancho
02/26/2019, 3:42 AMExceptions 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;
}
josephivie
02/26/2019, 4:00 AMcause
, and then thrown.juancho
02/26/2019, 4:10 AMnatpryce
02/26/2019, 8:55 AMjuancho
02/26/2019, 4:35 PM