码迷,mamicode.com
首页 > 其他好文 > 详细

Kotlin基础-异常处理错误

时间:2017-06-23 17:25:29      阅读:138      评论:0      收藏:0      [点我收藏+]

标签:array   color   rgs   pre   int   val   catch   size   str   

/*
*对可能发生执行异常的代码的一种保护措施
* 默认异常类 :EXception
*
*
* */
fun main(args: Array<String>) {

    //直接展示错误
    try {
        "abc".toInt()
    }catch (e:Exception){
        print(e)
    }
    //忽略错误
    val a:Int?=try{
        "3ss".toInt()
    }catch (e:Exception){
        null
    }
}

 

Kotlin基础-异常处理错误

标签:array   color   rgs   pre   int   val   catch   size   str   

原文地址:http://www.cnblogs.com/my334420/p/7070858.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!