Dec 2026 · Guide · ~7 min read
React Error Boundaries — What They Catch and What They Don't
By Safdar Ali — frontend engineer, Bengaluru
I'm Safdar Ali. An error boundary is a component that catches a JavaScript error in its child tree during render and shows a fallback instead of unmounting the whole app. In the App Router, error.js is that boundary for a route segment.
It does not catch errors inside event handlers, async code, or the server's own logging. A click handler needs its own try/catch and a message in the UI. People wrap the page in a boundary and then wonder why the button failure still vanished into the console.
Put the boundary where a failure should be contained. A broken widget should not take down the article. A broken article can take down the article route and leave the nav, which lives in a parent layout that did not error.
The fallback needs a way forward: retry, or a link home. A sentence that says "something went wrong" with no action is a dead end. Log the error on the server or your error reporter so you hear about it before the user emails you.
Do not catch errors by rendering null. That hides the bug and leaves a hole. Show the fallback and fix the throw.
If this helped you
I publish free tutorials and write-ups like this in my spare time — no paywall on the guides. If it saved you an afternoon of trial and error, you can support the work:
- Buy me a coffee at buymeacoffee.com/safdarali
- Subscribe to my YouTube channel — it's free; 70+ React & Next.js tutorials
Related reading
More guides on safdarali.in — same author, production-focused.
- Guide
How to Build a Frontend Developer Portfolio That Stands Out
Frontend developer portfolio guide for India — sections, React/Next.js examples, SEO, performance, personal branding, FAQ, and checklist to build and rank.
May 2026Read article →
- Guide
React Server Components vs Client Components — When to Use Which
Practical RSC vs client guide for Next.js App Router — when to use each, real code, bundle before/after, and performance impact.
May 2026Read article →