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
    }
}
原文地址:https://www.cnblogs.com/my334420/p/7070858.html