java - 将 Java 中的 try catch 重写为 Kotlin
问题描述
想把java try catch 改写成Kotlin。如果出现错误,只需要记录一个状态。将 Arrow 与 kotlin 一起使用是否过大?
Kotlin/Arrow 中的示例实现:
fun some_method(): <SomeReturnType>{
Try.invoke {
//code which will return SomeReturnType
}.getOrElse { throwable ->
when (throwable) {
is RuntimeException -> {
// do something
}
is SomeOtherEception -> {
// do something
}
else -> {do something}
}
}
}
解决方案
推荐阅读
- maven - 目前有什么方法可以使用 Artifact Registry 镜像官方 maven repo?
- c# - 如何确定在关机时调用 IHostedServices 的顺序?
- c# - 协程只执行一次
- python - 使用 zipfile 在 python 中创建文件夹的 zip
- javascript - 素材UI卡根据输入变化
- mongodb - MongoDB docker错误:无法打开/var/log/mongodb/mongod.log
- python - 如何正确更新 QLabel 图像?
- python - 测试发现从相对导入中删除 Python 命名空间?
- ios - 与“applinks:”相关的域在开发中不起作用
- jquery - Remove Sibling 正在删除 jquery 中的额外元素