小编Ser*_*pin的帖子

即使包含在 try catch 中,Kotlin SupervisorScope 也会失败

考虑这样的代码:

\n
coroutineScope {\n  try {\n    supervisorScope { launch { error("") } }\n  } catch (t: Throwable) {\n    println("logs and stuff")\n  }\n}\n
Run Code Online (Sandbox Code Playgroud)\n

运行此代码,我希望logs and stuff在输出中看到,但它会将异常一直传播到原始范围,除非已CoroutineExceptionHandler安装,否则它将失败。

\n

问题是:这是设计使然,还是一个错误(如果是这样,\xe2\x80\x94 将打开一个问题)?

\n

PS 切换到内部coroutineScope“修复”问题

\n
coroutineScope {\n  try {\n    coroutineScope { launch { error("") } }\n  } catch (t: Throwable) {\n    println("now you\'ll see it")\n  }\n}\n
Run Code Online (Sandbox Code Playgroud)\n

kotlin kotlin-coroutines

6
推荐指数
1
解决办法
370
查看次数

标签 统计

kotlin ×1

kotlin-coroutines ×1