当前位置: 首页 > news >正文

runCatching异常捕获onSuccess/onFailure返回函数,Kotlin

runCatching异常捕获onSuccess/onFailure返回函数,Kotlin

 

fun test(a: Int, b: Int) {runCatching {a / b}.onSuccess {println("onSuccess: $it")return ok(it)}.onFailure {println("onFailure: $it")return fail(it)}
}fun ok(o: Any) {println("ok: $o")
}fun fail(o: Any) {println("fail: $o")
}fun main(args: Array<String>) {test(0, 1)test(1, 0)
}

 

onSuccess: 0
ok: 0
onFailure: java.lang.ArithmeticException: / by zero
fail: java.lang.ArithmeticException: / by zero

 

 

 

 

Kotlin异常处理runCatching,getOrNull,onFailure,onSuccess(1)-CSDN博客文章浏览阅读533次。b-catch: java.lang.RuntimeException: b发生异常。kotlin异常处理try-catch-finally。kotlin异常处理try-catch-finally_zhangphil的博客-CSDN博客。https://blog.csdn.net/zhangphil/article/details/133279853Kotlin异常处理runCatching,getOrDefault,getOrNull run(2)-CSDN博客文章浏览阅读93次。b-catch: java.lang.RuntimeException: b发生异常。kotlin异常处理try-catch-finally。kotlin异常处理try-catch-finally_zhangphil的博客-CSDN博客。b-catch: java.lang.RuntimeException: b发生异常。kotlin异常处理try-catch-finally。kotlin异常处理try-catch-finally_zhangphil的博客-CSDN博客。https://blog.csdn.net/zhangphil/article/details/133279933

 

http://www.lryc.cn/news/262705.html

相关文章:

  • IDEA报错处理
  • 使用动画曲线编辑器打造炫酷的3D可视化ACE
  • 使用 React 和 ECharts 创建地球模拟扩散和飞线效果
  • http状态码(一)400报错
  • 【深度学习目标检测】五、基于深度学习的安全帽识别(python,目标检测)
  • 芒果RT-DETR改进实验:深度集成版目标检测 RT-DETR 热力图来了!支持自定义数据集训练出来的模型
  • c语言实验八
  • ArcGIS Pro SDK文件选择对话框
  • ACT、NAT、NATPT和EASY-IP
  • HTML实现每天单词积累
  • 【ECMAScript笔记二】运算符分类,流程控制(顺序结构、分支结构、循环结构)
  • ShenYu网关注册中心之Zookeeper注册原理
  • 高级C#技术(二)
  • 【性能测试】基础知识篇-压力模型
  • springboot-redis设置定时触发任务详解
  • Video anomaly detection with spatio-temporal dissociation 论文阅读
  • svn 安装
  • slurm 23.11.0集群 debian 11.5 安装
  • ffmpeg可以做什么
  • 一种缩小数据之间差距的算法
  • 【Axure RP9】动态面板使用------案例:包括轮播图和多方式登入及左侧菜单栏案例
  • 在接口实现类中,加不加@Override的区别
  • 优质全套SpringMVC教程
  • 微信小程序---使用npm包安装Vant组件库
  • GPT-4V被超越?SEED-Bench多模态大模型测评基准更新
  • 数据库_mongoDB
  • Layui实现自定义的table列悬停事件并气泡提示信息
  • Tomcat从认识安装到详细使用
  • 07-Eventing及实践
  • Linux下Netty实现高性能UDP服务