Skip to Content
Mastering Functional Programming
book

Mastering Functional Programming

by Anatolii Kmetiuk
August 2018
Intermediate to advanced
380 pages
10h 2m
English
Packt Publishing
Content preview from Mastering Functional Programming

Error

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning Functional Programming

Learning Functional Programming

Jack Widman

Publisher Resources

ISBN: 9781788620796Supplemental Content