Kotlin基础-异常处理错误

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

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

 

posted @ 2017-06-23 17:07  张兮兮  阅读(363)  评论(0编辑  收藏  举报