Lesson 4.1

Error boundaries and instrumentation

An error file wraps its segment in a boundary, so a crash in one panel leaves the rest of the page usable and offers a retry.

14mIntermediate9.8k students

Overview

Failing in one place instead of everywhere

An error file wraps its segment in a boundary, so a crash in one panel leaves the rest of the page usable and offers a retry. Without it, a single thrown error replaces the whole application with a blank screen.

Boundaries are per segment, which means placement is a design decision. A boundary at the root is a safety net; a boundary around each widget is a resilient dashboard.

Expected failures are not errors. A record that does not exist should call notFound(), not throw — mixing the two floods your error reporting with 404s and buries the real bugs.

In this lesson you will:

  • Contain a render error to one segment
  • Report errors somewhere you will actually see them
  • Distinguish expected failures from bugs

Resources

Previous Lesson
Next Lesson
Error boundaries and instrumentation — Next.js for Production — Vertex