Tsallaka zuwa abun ciki
Justice Tech School

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

Is try an expression in Kotlin?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.