5 kotlin之 try catch
kotlin的try catch比Java更简洁面料采用,使用更方便
val value = "10a"
var out: Int? = null
//错误处理
try {
out = Integer.parseInt(value)
} catch (e: NumberFormatException) {
println("NumberFormatException")
println(e.message)
} catch (e: Exception) {
println("Exception")
println(e.message)
} finally {
println("out is $out")
}
//赋值处理
var outPut = try {
Integer.parseInt(value)
} catch (e: Exception) {
-1
}
println("output is $outPut")
image
喜欢可以加Q群号:874826112,一起学习,成长,交流工作经验,
记得要点赞,评论哦😯;
更多相关内容请点击主页查看,有你想不到的惊喜😂....
简书: https://www.jianshu.com/u/88db5f15770d
网友评论