Kotlin教程:try...catch块异常处理解决方案
Kotlin try-catch
块用于代码中的异常处理。 try
块包含可能抛出异常的代码,catch
块用于处理异常,必须在方法中写入此块。 Kotlin try
块必须跟随catch
块或finally
块或两者。
使用catch块的try语法
try{
//code that may throw exception
}catch(e: SomeException){
//code that handles exception
}