October 2018
Intermediate to advanced
370 pages
9h 15m
English
When we run program code, we deal with expressions and statements all the time. It's very important to understand the difference between these. Let's look at the following code:
1 + 1
This code is an expression because it contains variables, operators, and returns a single result. If a standalone element of program code represents an action, it is a statement:
println("Hello")
In the context of this section, the main point for us is that an expression returns something. In Kotlin, the try { ... } catch { ... } finally { ... } block is an expression and we can write something like this:
fun loadValue(): Int = throw Exception()fun main(args: Array<String>) { println(try { loadValue() } catch (exception: ...
Read now
Unlock full access