An error boundary is a class component that defines static getDerivedStateFromError(error). When a descendant throws while React is working on the tree, React unwinds to the nearest boundary and renders its fallback in place of that subtree; the rest of the page keeps working.
getDerivedStateFromError(error)runs during rendering and returns state that switches to the fallback. It must be pure: React may call it more than once.componentDidCatch(error, info)runs in the commit, once, for side effects such as reporting;info.componentStacksays where it happened.
Caught: errors thrown while rendering descendants, in their lifecycle methods and Effects, from use with a rejected promise, from a lazy component whose load failed, and from a Transition started with useTransition's startTransition, which is how errors in Actions reach the boundary.
Not caught:
- Event handlers. They run after rendering, outside React's work; use
try/catch, or put the error in state and render it. - Asynchronous code:
setTimeout, promise callbacks, code afterawait. The boundary has the same limit astry/catch: it only sees throws while React is calling your code. - The boundary's own errors. They go to the next boundary up.
- Server rendering. There, a server error falls back to the nearest
<Suspense>and the client retries.
There is no Hook equivalent in React 19.3.1; write one boundary class (or use a library) and reuse it.
Uncaught errors unmount the whole root: the container is left empty. Reporting changed in React 19: errors are no longer rethrown. Caught errors go to console.error, uncaught ones to window.reportError, which fires the window error event. createRoot (and hydrateRoot) accept onCaughtError, onUncaughtError and onRecoverableError to send them to monitoring instead.