Skip to content

Commit dc24a1d

Browse files
Code before exception handling module
1 parent 5a4df8d commit dc24a1d

File tree

1 file changed

+22
-0
lines changed
  • app/src/main/java/com/lukaslechner/coroutineusecasesonandroid/playground/flow/exceptionhandling

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.lukaslechner.coroutineusecasesonandroid.playground.flow.exceptionhandling
2+
3+
import kotlinx.coroutines.coroutineScope
4+
import kotlinx.coroutines.flow.Flow
5+
import kotlinx.coroutines.flow.flow
6+
import kotlinx.coroutines.launch
7+
8+
suspend fun main(): Unit = coroutineScope {
9+
10+
launch {
11+
stocksFlow()
12+
.collect { stock ->
13+
println("Collected $stock")
14+
}
15+
}
16+
}
17+
18+
private fun stocksFlow(): Flow<String> = flow {
19+
emit("Apple")
20+
emit("Microsoft")
21+
throw Exception("Network request failed")
22+
}

0 commit comments

Comments
 (0)