https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
n

niqo01

11/28/2019, 2:45 AM
I am seeking for advice, best practice to handle exceptions where the logic to handle exceptions is in common code and the exceptions are thrown by SDKs implemented in each platforms. I would like to have logic like if an exception is of one type then do X otherwise do Y.
s

Sam

11/28/2019, 3:04 AM
Can you declare your exceptions in common code? Then your platform code can just throw them as needed.
n

niqo01

11/28/2019, 4:01 AM
Is the practice of declaring exception in common code and mapping the SDK generated ones into those the recommended approach? I should look into what ktor is doing
s

Sam

11/28/2019, 4:02 AM
Maybe a more concrete example of a problem you're trying to solve would be helpful.
n

niqo01

11/28/2019, 4:23 AM
I have several use cases. One of them is a presenter in common code which execute various tasks with one of them being an API call. On the jvm various exception can be returned extending
<http://java.io|java.io>.IOException
or not. I could catch the specific IOException related to no connectivity and ask the user to check their network settings, I could also catch the IOException related to network issues and ask the user to retry and just re-throw if this is not an IOException. Another use case is about the Firestore database which offers and SDK for each platform. Requesting cache data which does not exist return FirebaseException with a specific property which I would like to capture and run different logic based on the cause. I actually don't see any other ways than creating my own common code exception and map each platform one to the common one.
g

Gabriel Feo

11/30/2019, 1:39 AM
Yeah, I think you'll have to map an
actual typealias
to the
java.io.IOException
👍 1
11 Views