我无法理解catch运算符在 kotlin 中的工作原理Flow。
这是捕获文档
问题:
catch在Flow遇到异常时继续,而不是完成?catch似乎改变了行为。为什么我不能将catch运算符放在链的末尾以看到相同的结果?在我的示例中,只有当我将其放置在 BEFORE 之前,它才会执行onEach。第一个例子,放置catchBEFORE onEach:
fun main() {
// Flow of lambdas that return a String (or throw an Exception)
flowOf<() -> String>({ "Hello " }, { error("error") }, { "World" })
// Map to the result of the invocation of the lambda
.map { it() }
// This line will emit the error …Run Code Online (Sandbox Code Playgroud)