File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed
app/src/main/java/com/lukaslechner/coroutineusecasesonandroid/playground/flow/exceptionhandling Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change 1+ package com.lukaslechner.coroutineusecasesonandroid.playground.flow.exceptionhandling
2+
3+ import kotlinx.coroutines.coroutineScope
4+ import kotlinx.coroutines.flow.flow
5+
6+ suspend fun main (): Unit = coroutineScope {
7+
8+ flow {
9+ try {
10+ emit(1 )
11+ } catch (e: Exception ) {
12+ println (" Catch exception in flow builder." )
13+ }
14+ }.collect { emittedValue ->
15+ throw Exception (" Exception in collect{}" )
16+ }
17+ }
Original file line number Diff line number Diff line change 1+ package com.lukaslechner.coroutineusecasesonandroid.playground.flow.exceptionhandling
2+
3+ import kotlinx.coroutines.coroutineScope
4+ import kotlinx.coroutines.flow.flow
5+
6+ suspend fun main (): Unit = coroutineScope {
7+
8+ flow {
9+ emit(1 )
10+ emit(2 )
11+ emit(3 )
12+ }.collect {
13+ println (" Collected $it " )
14+ }
15+ }
16+
17+ val inlinedFlow = flow<Int > {
18+ println (" Collected 1" )
19+ println (" Collected 2" )
20+ println (" Collected 3" )
21+ }
You can’t perform that action at this time.
0 commit comments