美文网首页
kotlin try catch使用方法

kotlin try catch使用方法

作者: 张漂亮1号 | 来源:发表于2020-05-22 14:38 被阅读0次

    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

    csdn:https://me.csdn.net/beyondforme

    掘金:https://juejin.im/user/5e09a9e86fb9a016271294a7

    相关文章

      网友评论

          本文标题:kotlin try catch使用方法

          本文链接:https://www.haomeiwen.com/subject/pfmqahtx.html