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  
}