Complete the code to catch exceptions in a Flow using the catch operator.
flowOf(1, 2, 3) .[1] { e -> emit(-1) }
The catch operator is used to handle exceptions in a Flow.
Complete the code to emit a fallback value when an exception occurs in the Flow.
flow {
emit(1)
throw RuntimeException("Error")
}.catch { [1] -> emit(0) }The lambda parameter in catch is commonly named e to represent the exception.
Fix the error in the code to properly handle exceptions in the Flow.
flow {
emit(1)
throw Exception("Fail")
}.[1] { e -> emit(-1) }The correct operator to handle exceptions in a Flow is catch.
Fill both blanks to emit values and handle exceptions with catch.
flow {
emit(10)
emit(20)
throw Exception("Oops")
}.[1] { e ->
emit([2])
}Use catch to handle exceptions and emit a fallback value like -1.
Fill all three blanks to create a Flow that emits numbers, handles exceptions, and collects the results.
val flow = flow {
emit(1)
emit(2)
throw Exception("Error")
}
flow.[1] { e ->
emit([2])
}.[3] { value ->
println(value)
}Use catch to handle exceptions, emit a fallback value 0, and then collect to process the emitted values.