try, catch and finally
try is an expression. catch handles errors and finally always runs.
Example
val n = try { "abc".toInt() } catch (e: NumberFormatException) { -1 } finally { println("done") }
println(n)Exercise
Always runs.
try {} {}
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.