Stylianos Gakis
03/13/2024, 12:19 AMdo { for await item in flow … } catch { here there was a cancellation on Kotlin side }
?
Am I missing some part of the docs that I should look at instead?itshan
03/13/2024, 2:18 AMkotlin.coroutines.cancellation.CancellationException: StandaloneCoroutine was cancelled
after you cancel the job.
job?.cancel()
job = flow<String>{}
.catch { e ->
when (e) {
sideEffectFlow.emit("to notify the UI about the error")
}
}
.onCompletion {
if (it != null) {
// some error occurred
} else {
// completed without error
}
}.launchIn(this)
Filip Dolník
03/13/2024, 7:52 AMwithTaskCancellationHandler
. However, in most cases you don’t have to do anything because the iteration will stop on its own.Stylianos Gakis
03/13/2024, 8:08 AMDougie
03/27/2024, 8:22 AMFilip Dolník
03/27/2024, 8:36 AMtry
syntax from Swift.
The alternative is that the exception is converted into a fatal error. This is the default behavior and to get the first one you need to annotate the method that produces the error with the @Throws
annotation and give it the specific exceptions you want to be converted.
So to get exception handling in Swift you would have to annotate the last Kotlin function that is called from Swift (where the crash happens). However, in the case of Flows that is some internal function provided by a library so you can’t do that.
Long story short, Flows do not support custom exception propagation (with or without SKIE). You need to handle the exception inside Kotlin and pass it to Swift in some way if needed. The common way to do this is to use the Result pattern.Dougie
03/27/2024, 9:18 AM