6 Error handling

In this chapter you will learn

  • how to handle all errors without nulls and exceptions
  • how to make sure all corner cases are handled
  • how to indicate all the possible errors in the function signature
  • how to compose bigger functionalities from smaller functions in the presence of different possible errors
  • how to return user-friendly and descriptive errors

There are two ways to write error-free programs; only the third one works.

—Alan Perlis, “Epigrams on Programming”

Handling lots of different errors, gracefully

We can’t write code that never fails. That’s why we need to embrace all possible errors and make sure our code can handle them and recover from them gracefully. In this chapter we will discover how helpful it is to think ...

Get Grokking Functional Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.