Chapter 6. Process Error Handling

Whatever the programming language, building distributed, fault-tolerant, and scalable systems with requirements for high availability is not for the faint of heart. Erlang’s reputation for handling the fault-tolerant and high-availability aspects of these systems has its foundations in the simple but powerful constructs built into the language’s concurrency model. These constructs allow processes to monitor each other’s behavior and to recover from software faults. They give Erlang a competitive advantage over other programming languages, as they facilitate development of the complex architecture that provides the required fault tolerance through isolating errors and ensuring nonstop operation. Attempts to develop similar frameworks in other languages have either failed or hit a major complexity barrier due to the lack of the very constructs described in this chapter.

You might have heard of the “let it crash and let someone else deal with it” and “crash early” approaches. That’s the Erlang way! If something goes wrong, let your process terminate as soon as possible and let another process deal with the problem. The link/1 BIF will have been used by this other process to allow it to monitor and detect abnormal terminations and handle them generically.

The link/1 BIF takes a pid as an argument and creates a bidirectional link between the calling process and the process denoted by the pid. The spawn_link/3 BIF will yield ...

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