error boundary
A class component that catches errors thrown while rendering its children and shows a fallback UI instead of crashing the whole app.
In more detail
It uses static getDerivedStateFromError to switch to the fallback and componentDidCatch to report the error. It does not catch errors in event handlers, in asynchronous code such as timers, in server rendering or in itself. Changing its key, or resetting its state, lets the user retry.
Related terms
- error.tsx — A special file that wraps a route segment in an error boundary and renders its component when something below it throws.
- global-error.tsx — The error boundary for the root layout itself, which replaces the whole page when the root layout crashes.
- reset function — The function error.tsx receives that re-renders the failed segment to try again.
- getDerivedStateFromError — A static class method React calls after a child throws during rendering, returning new state so the boundary renders its fallback.
- componentDidCatch — A class lifecycle method React calls after a child error, receiving the error and an info object whose componentStack shows which components were rendering.
- fallback UI — The placeholder content React shows instead of part of the tree, either while it loads (Suspense) or after it crashes (error boundary).
- class component — The older way to write a React component, as a JavaScript class with a render method and lifecycle methods.
Taught in
- Parallel & Intercepting Routes: Modals & Split Views — Next.js 15 & Modern App Router Architecture
- Granular Suspense: Resolving Waterfall Bottlenecks — Next.js 15 & Modern App Router Architecture
- Error Boundaries: Nested error.tsx & Reset Logic — Next.js 15 & Modern App Router Architecture
- Not Found Handling: not-found.tsx & Programmatic Exits — Next.js 15 & Modern App Router Architecture
- The use() Hook: Reading Promises And Context Directly — React 19 & Modern Component Architecture
- Code-Splitting with React.lazy: Dynamic Imports And Chunks — React 19 & Modern Component Architecture
- Error Boundaries: componentDidCatch And Fallback UI Trees — React 19 & Modern Component Architecture