kotlin - 如何在 CoroutineExceptionHandler 中捕获特定异常
问题描述
我有这个 CoroutineExceptionHandler:
private val handler: CoroutineExceptionHandler = CoroutineExceptionHandler{ _, exception ->
println(“Exception thrown in one of the children: $exception”)
}
我可以捕获特定的异常吗(例如使用 try...catch),例如我想捕获 java.net.SocketException。尝试...绕过代码不起作用,我想在服务器关闭连接时提醒用户。
解决方案
推荐阅读
- kotlin - 如何在 Kotlin 中指向名称不明确的变量?(这个,标签或使用其他东西)
- javascript - 如何使 HTML 按钮引用外部 javascript 文件中的操作?
- docker - 如何验证分离的命令是否在容器中运行
- excel - 如何让 excel 为丢失的行返回 NA
- ios - AudioKit:交叉淡入淡出 2 AKPlayer
- java - 为什么我的 javafx imageview 会扭曲我的 gif 播放方式
- javascript - React JS - 如何在状态更新之前防止渲染 [Hooks]
- javascript - base 64 字符串的字符长度是多少
- google-sheets - 如何使用 Google 表格下拉菜单显示全名存储短名称
- javascript - 更改图标的功能不起作用 marker.setIcon