Is it possible to handle unhandled exceptions within Aura Lightning Components client-side javascript code, without wrapping every piece of code in try/catch?

We have a few old LCs which operate on large data sets, and sometimes hit heap size or just normal javascript undefined errors (ex. [Cannot read property 'toLowerCase' of undefined]). When this happens, the user loses all the work done on the LC and they have to reload the page.

Hoping if the Aura framework provides a way to trigger a controller method (similar to aura:systemerror, which fires on server-side exceptions), where we can handle those errors, and save the current work in a draft.



If an error sufficiently powerful enough to cause you to need to reload, Aura won't be able to save you. Your only option is to add an error handler event yourself:

window.addEventListener('error', helper.errorHandler.bind(this, component));

This will allow you to take an action, such as saving the data to window.sessionStorage, or attempting to recover by calling an event. Again, this won't work if the entire engine dies for some reason, but it can be a starting point.

As an aside, you can rather easily convert to a session-backed value provider in some cases. This can be used to keep track of the state.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.