7 Error handling and logging
This chapter covers
- An idea of exceptions in Haskell and when to use them
- Several exception-handling mechanisms
- Designing exception handling in pure and impure code
Programmers want to control everything within their programs. In Haskell, we can do that via type discipline and reasoning about function behavior. Unfortunately, communication with the outer world sets limits to that control as follows:
-
When reading a file, we can never be sure in advance whether it exists.
-
Even if it does exist, we have no guarantee its content matches our expectations.
-
While we are fetching a web page, a network connection may break.
-
Acquiring a resource (even memory allocation) may fail.
How should we react? When can ...
Get Haskell in Depth 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.