NextPlayground

Error Boundaries (error.tsx)

An error.tsx file placed in a route segment automatically wraps that segment (and its children) in a React Error Boundary. When a component throws during render, the boundary catches it and renders the fallback UI instead of crashing the whole app. The fallback receives the error plus a reset() function that re-renders the segment to attempt recovery. The counter below throws once it reaches 5 — trip it, then use “Try again” on the fallback to reset.

nextjs.org/docs/app/building-your-application/routing/error-handling

Buggy counter

5 left

0

Incrementing to 5 throws during render. The nearest error.tsx boundary will take over.

Error Boundaries Demo