React & Modern Frontend (445 Qs)•Part 8: Advanced React Patterns, Portals & Performance (152 - 261)
In which scenarios do error boundaries not catch errors?
Below are the cases in which error boundaries don't work,
- Inside Event handlers
- Asynchronous code using setTimeout or requestAnimationFrame callbacks
- During Server side rendering
- When errors thrown in the error boundary code itself
Practical Code Example
jsx
// Error Boundaries do NOT catch errors in:
// 1. Event handlers (use try/catch inside onClick)
// 2. Asynchronous code (setTimeout, requestAnimationFrame)
// 3. Server-side rendering (SSR)
// 4. Errors thrown inside the Error Boundary component itself