8 Functional error handling

This chapter covers

  • Representing alternative outcomes with Either
  • Chaining operations that may fail
  • Distinguishing business validation from technical errors

Error handling is an important part of our applications. It’s also one aspect in which the functional and imperative programming styles differ starkly:

  • Imperative programming uses special statements like throw and try-catch, which disrupt the normal program flow. This introduces side effects as discussed in section 3.1.1.

  • Functional programming strives to minimize side effects, so throwing exceptions is generally avoided. Instead, if an operation can fail, it should return a representation of its outcome, including an indication of success or failure, as ...

Get Functional Programming in C#, Second Edition 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.