Skip to content

Commit 167cad9

Browse files
Code before exception transparency lecture
1 parent e423a67 commit 167cad9

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
}

0 commit comments

Comments
 (0)