Chapter 5. Concurrent error-handling and fault tolerance with links, monitors, and processes
This chapter covers
- Handling errors, Elixir style
- Links, monitors, and trapping exits
- Implementing a supervisor
Ever watched The Terminator, the movie about an assassin cyborg from the future (played by Arnold Schwarzenegger)? Even when the Terminator is shot multiple times, it just keeps coming back unfazed, over and over again. Once you’re acquainted with Elixir’s fault-tolerance features, you’ll be able to build programs that can handle errors gracefully and take corrective actions to fix the problems. (You won’t be able to build Skynet, though—at least, not yet.)
In sequential programs, there’s typically only one main process doing all the hard work. What happens if this process crashes? Usually, this means the entire program crashes. The normal approach is to program defensively, which means lacing the program with try, catch, and if err != nil.