Kotlin miniguide #4 Handling exceptions

Try/catch can be used as expressions:


val ret:Int? try {
   Integer.ParseInt(some string)
} catch (e: NumberFormatException ) {
   null
}

Kotlin supports the Java exception hierarchy but exceptions are unchecked.

Lascia un commento