bj0
11/18/2024, 6:24 PMflow
from within with an error? just throw an exception, or is there a function?kevin.cianfarini
11/18/2024, 7:03 PMflow {
coroutineScope {
try {
...
} catch (e: SomeException) {
// ... perform some side effect...
cancel(message = "An error happened", cause = e)
}
}
}
bj0
11/18/2024, 9:46 PMcancel
will it consider a "normal" cancellation? so when you use .catch()
on the flow later, it won't trigger will it?bj0
11/18/2024, 9:54 PMephemient
11/19/2024, 6:00 AMflow {
throw exception // will end flow
}.catch {
// will catch exception
}
ephemient
11/19/2024, 6:02 AMcoroutineScope
inside flow
makes it way too easy to do things that aren't supported and will throw errors at runtime (such as trying to emit from another coroutine), I wouldn't do that. if you want to end the flow gracefully, you can return@flow
kevin.cianfarini
11/19/2024, 2:03 PMFlow.first
, would throw exceptions.