Aura Client Side Javascript Unhandled Exceptions

All we need is an easy explanation of the problem, so here it is.

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.


How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

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.

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply