Catch exceptions

Report a typo

Someone provided us a flow, but we don't know if it's safe to use because it may throw an exception sometimes; moreover, processing is also an unsafe operation.

Make sure that if the code throws an exception, the flow collection stops safely and no error is printed or re-thrown.

Tip: A `.catch` operator can be used with an empty lambda

Write a program in Kotlin
fun main() = runBlocking {
// add error handling without changing existing operators
// no need to do anything with the error, ignore it
dangerousFlow
.map { data -> process(data) }
.collect { data -> store(data) }
}
___

Create a free account to access the full topic