September 2018
Intermediate to advanced
398 pages
9h 43m
English
In order to illustrate how exceptions bubble up the call stack, we are going to create a new averageAge function, which calculates the average age of a list of Person instances, using their string descriptions, as shown in the following code:
def averageAge(descriptions: Vector[String]): Double = { val total = descriptions.map(createPerson).map(_.age).sum total / descriptions.length}
This function calls our previously implemented createPerson function, and therefore will throw any exception that is thrown by createPerson because there is no try...catch block in averageAge.
Now, we can implement another function on top that will parse an input containing several Person descriptions and return a summary in a string. It will ...
Read now
Unlock full access