DEV Community

Discussion on: What is the benefit of Functional Programming?

cullophid profile image
Andreas Møller

Throwing an exception violated the contract of a function.
Take the function Number -> Number. It takes a number as input and returns a number.
If the function throws an exception it will no longer return a number and will therefor violate its contract.
That is why you use complex types for error handling in functional languages:
Number -> Either Err Number
This function now returns an Either type that can either be an error or a Number. Notice that we can now handle exceptions, but we still do not "throw".