Skip to main content

What types of errors does an Error Boundary catch?

Errors that an Error Boundary does catch

Error typeWhere it happensExampleCaught?
An error during renderingduring a child component's render()return user.name; // user = undefinedYes
An error in a class constructorinside a component's constructor()constructor() { throw new Error("fail"); }Yes
An error in lifecycle methodscomponentDidMount, componentDidUpdate, etc.componentDidMount() { throw new Error(); }Yes
An error in hooks (during render)useMemo, useState, useEffect, etc. (if thrown during render)throw new Error("error in useMemo")Yes
An error in descendants (child components)in any component inside the <ErrorBoundary> treeChild -> GrandchildYes
An error in a Suspense fallback / lazy componentwhile loading a lazy componentReact.lazy(() => import('./Broken'))Yes (through the nearest Error Boundary)

Errors that an Error Boundary does not catch

Error typeWhere it happensExampleCaught?What to do
Errors in event handlersinside onClick, onChange, etc.<button onClick={() => { throw new Error(); }}>NoUse try...catch inside the handler
Errors in async codesetTimeout, Promise, async/await, fetchsetTimeout(() => { throw new Error(); })NoCatch it with try...catch or .catch()
Errors inside the Error Boundary itselfinside the render, componentDidCatch, fallback methodsNoWrap the Error Boundary in another Error Boundary
Errors during server-side rendering (SSR)when running on the serverNoLog them through a server-side handler
Errors in layout effects / cleanupinside a useEffect cleanupNo (React 18 changed this partially, but do not rely on it)try/catch inside the effect
Errors outside React (external libraries, window)for example, in addEventListener or window.onerrorNoUse global error handlers (window.onerror, window.onunhandledrejection)

Why it does not catch events and async code

Because an Error Boundary only handles synchronous errors within React's render cycle. Errors in events and async callbacks happen after the render has already finished, outside React's call stack, so React does not even "see" that they occurred.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.