React · Middle · Question 15 of 75
Which errors does an error boundary NOT catch?
- 1Errors while rendering child components
- ✓Correct answer: Errors in event handlers and async code
- 3Errors in descendants' lifecycle methods
Explanation
An error boundary catches errors during render, in constructors and in descendants' lifecycle methods. Errors in onClick, setTimeout and promises happen outside render - handle them with try/catch or put them into state to throw during render. A boundary is a class component with getDerivedStateFromError; react-error-boundary is often used.