hi guys hope you are all doing well ... is there a...
# multiplatform
a
hi guys hope you are all doing well ... is there anyway that I can handle exceptions globally and protect my app from crashing in compose multiplatform ?
s
If your app doesn't crash, it may likely get into an undefined state. Is this what you (and your app's users) want?
☝️ 1
a
@streetsofboston actually no .... I want to wrap my app with error handler that catch any unhandled exception and just say something to the user and send this error to my crashlytics instead of crashing
s
And then what does the user do? After that exception/throwable is caught and the message is shown, the app is likely in an un-usable state. When the user dismisses the error-msg screen, then how can the user continue in an app that has an undefined/unexpected state?
a
the message can say something like this service is down now please try later or anything ... but at least the app didn't crash
s
If the service is down, then it's not a crash, not an exception. It is a proper use-case that would need to be handled explicitly.
If you use exceptions/throwables for error handling, i.e. for recoverable error/not-so-good-path situations, catch them explicitly where needed and handle those properly. Any other exception/throwable should throw an exception, since you didn't expect them.
A 'catch all and any throwable and ignore' (after showing a msg to the user or not) is asking for problems 🙂 The app can be left in an unexpected/undefined/unusable state and your user won't like it.
In Android, you could install an Uncaught-Exeption-Handler, but in iOS (Swift) you can't do this at all (for the reasons I described above).