chapter seven
7 Errors
This chapter covers
- How errors serve recovery and debugging needs
- Why stack traces cost memory and performance
- Placing error handlers at semantic boundaries
- When async operations break error propagation
- Leveraging global error handlers as a last resort
JavaScript errors are more complicated than they seem.
So far throughout this book, we’ve built up JavaScript’s execution model piece by piece. We’ve looked at how values live in memory, how scopes control access, how objects organize data, and how functions operate on data. Each layer adds complexity and each complexity adds a new way for things to go wrong. When they do go wrong, JavaScript’s error system takes over. However, most developers are surprised to find just how little the language specification has to say about errors! What developers actually encounter when their code fails is typically an intricate web of engine and runtime-specific behaviors and historical accidents.