4 ms·
This is not meant for user errors. This feature is for gracefully recovering from JavaScript errors that occur in production as a result of programmer mistakes
by danabramov 9y ago
This is not meant for user errors.
This feature is for gracefully recovering from JavaScript errors that occur in production as a result of programmer mistakes.
For example, Facebook heavily uses error boundaries in ads code. Even if one widget fails rendering, it doesn’t take down the entire page. You’re going to have some runtime errors if you use JavaScript, but this feature ensures you can gracefully recover from them (instead of just breaking the whole app as React 15 and earlier did).
There are two other effects of this change:
* React no longer has its own cryptic errors (because it doesn’t get “confused” when user code throws, and can cleanly fail fast if there is no error boundary).
* Errors reported to the boundaries have a component stack trace attached to that, so you can know where exactly in the hierarchy the failure occurred. This can be pretty useful when debugging.
I hope this helps!