Is their anything in web components (lit-html) like error boundary in React.
Looking for something equivalent, I've stumbled upon Salesforce's LWC errorCallback(): https://developer.salesforce.com/docs/component-library/documentation/lwc/lwc.create_lifecycle_hooks_error
Looking briefly at the implementation, it requires cooperation from the throwing component and the error boundary: the component will have its own methods catching exceptions, then walking up the DOM tree until it finds an error boundary (which it identifies as a LWC component –this itself is done through a field with a known Symbol– with a defined errorCallback() method); so it will only works between two LWC components.
To make it work across component frameworks, I suppose one could dispatch an ErrorEvent from a component (this still requires components to handle their errors to dispatch that event) and have it bubble the DOM tree up to the error boundary component which would handle it (and stopPropagation()).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With