I'm working on a complex web application written in Sencha Touch and PhoneGap. The way Sencha Touch applications are written makes it hard to surround every potential failure point with a try/catch, especially with asynchronous AJAX request handlers.
It's also critically important to detect when an unhandled exception occurs because it looks and feels like a native app with PhoneGap (i.e. we can't expect them to refresh the page and try again like in a web app you view in a regular browser).
Can you suggest a recommendation for how to deal with this scenario?
It's a great question. Of course the window error
event should never replace strategically placed try/catch
blocks or good use of error responses from HTTP requests, but until the mobile browsers catch up with the desktop versions, reporting back truly unexpected errors is near impossible.
I don't have time to test this out; so all I can suggest is a thought experiment at the moment for what is in all honesty probably a bad idea...
You could potentially write replacement functions for addEventListener
(and maybe dispatchMethod
) that could wrap the native functions / handler arguments with try/catch
and call a custom global error logger. Since there is no easy way to 'hook' these functions all at once, it would no doubt mean iterating over many of the native objects' prototypes on window
to perform the 'wrapping'. This could cover a large majority of exceptions that would currently go silent.
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