August 2018
Intermediate to advanced
380 pages
10h 2m
English
The first effect we will be discussing is the effect of an error. An error is produced when something goes wrong in your program. In imperative languages, it is usually modeled by an exception. An exception is a phenomenon produced by a line of the program that disrupts the execution flow of the program at that point. Usually, it propagates up the call stack, disrupting the execution at its parent call stacks too. If left unhandled, exceptions propagate to the topmost call-stack frame, and the program will crash.
Consider an example of division by zero:
def division(n1: Double, n2: Double): Double = if (n2 == 0) throw new RuntimeException("Division by zero!") else n1 / n2
We have a division function that checks whether its denominator ...