首页 > 解决方案 > 如何在 CoroutineExceptionHandler 中捕获特定异常

问题描述

我有这个 CoroutineExceptionHandler:

private val handler: CoroutineExceptionHandler = CoroutineExceptionHandler{ _, exception ->
println(“Exception thrown in one of the children: $exception”)
}

我可以捕获特定的异常吗(例如使用 try...catch),例如我想捕获 java.net.SocketException。尝试...绕过代码不起作用,我想在服务器关闭连接时提醒用户。

标签: kotlinexceptionkotlin-coroutines

解决方案


推荐阅读