Gleb
02/28/2024, 9:38 PMjava.net.ConnectException
As far as I understood from the several issue descriptions in various sources, this exception is uncatchable from commonMain. I'm trying to solve this by introducing expect/actual declarations for the exception, but running into a problem of not being able to make my actual declarations compatible.
My current code is something like this:
commonMain: expect class RequestTimedOutException: Exception
androidMain: actual class RequestTimedOutException: ConnectException()
But the code wouldn't compile, because "_Actual class 'RequestTimedOutException' has no corresponding expected declaration The following declaration is incompatible because some supertypes are missing in the actual declaration_", even though Kotlin's Exception is a typealias
of java.lang.Exception
Has anyone dealt with such a problem? How did you solve it? Is there a better solution for the underlying problem of handling the time out situation in commonMain?
Thanks
Upd: I figured doing some kind of a wrapper with expect/actual that catches the exception and then throws a different one that could be caught is working way to do it, but ideally I want to have something less sketchyMichael Krussel
02/28/2024, 9:49 PMException
to see if the exception was something I wanted to handle. I then checked that in the catch block and handled it differently than the other exceptions.
This was related to database things and not network, but the concept is the same.Gleb
02/28/2024, 9:58 PMcatch(e: Throwable)
and the app will still crashMichael Krussel
02/28/2024, 10:00 PMcatch(e: Throwable)
doesn't catch something on Android. I could see it not working on JS or iOS maybe.Gleb
02/28/2024, 10:05 PMGleb
02/29/2024, 7:47 AMMichael Krussel
02/29/2024, 2:38 PMGleb
02/29/2024, 8:21 PM