Hi all, how to catch exception thrown by `callback...
# coroutines
b
Hi all, how to catch exception thrown by
callbackFlow
?
Copy code
fun connect():Flow<Item> = callbackFlow {
    check(1 == 0) // This is expected to throw an IllegalStateException
}
l
Hi, just like for another flow, around the terminal operator (i.e.
collect { … }
or what's calling it under the hood, like
first()
or something else.
You can also use the
catch { … }
operator if it suits your use case.
b
i have
Copy code
connect()
.catch{}
.first()
but still can’t catch the exception
e
.first()
will fail if the flow is empty, as in your example. this is unrelated to the exception within your flow
☝🏼 1
☝️ 3