https://kotlinlang.org logo
#coroutines
Title
# coroutines
e

Eric Chee

02/22/2024, 7:32 PM
Is there a way to add a Coroutine ExceptionHandler when using onEach + launchIn? Context: I love using
flow.onEach{}.launchIn(scope)
over
scope.launch{ flow.collect{} }
because it makes it look cleaner (personal preference). But what i do miss is the ability to pass in a exception handler like
scope.launch(exceptionHandler) { ...collect()  }
. is there a way we can somehow add an exceptionhandler to Flow.launchIn() function?
e

ephemient

02/22/2024, 7:38 PM
.launchIn(scope + exceptionhandler)
should behave the same way
😮 1
e

Eric Chee

02/22/2024, 8:34 PM
Wow TIL something new. Thanks @ephemient! This is exactly what i wanted
b

baxter

02/24/2024, 5:18 AM
Why not just use
catch {}
on your flow?
e

Eric Chee

02/26/2024, 6:31 PM
we do use catch in a lot of places. But we have a lot of streams that are collected in a single component that we want each flows to be handled in a single source and it be nice to utilize the exception handler
👍 1