Consider an application that contains a number of pages with a relatively large amount of javascript present, or a predominantly JS powered application. The script handles a number things, such as:
- Client side validation
- Showing/hiding entry sections when appropriate
- Autocomplete when filling text fields
- Date pickers
etc.
If we consider the case that javascript is a requirement to use the site (e.g. not public internet site), I am wondering what the best practice would be for handling an unexpected error that occurs at runtime that causes some of the functionality to no longer be present (e.g. sections remain hidden, calendar controls become empty textboxes etc). The options that I can think of would be:
- Try to fail gracefully and have a page that will respond with no script present (gets trickier the more complex a page/app becomes).
or
- Try..Catch round all the critical code, and on error, display a message, or redirect to an error page.
I am curious if anyone has 'best practice' suggestions for this?
My motivation for looking into this comes after an obscure bug with an earlier version of jQuery for a user in IE10 running in compatibility mode. This question is not about that, but the knock on affect was that a lot of the code in a document ready handler in jQuery was not loaded, resulting in significant degredation in usability.