Windows 8 Development - Application Errors

13 June 2014

An event that is often overlooked, but which is extremely important for customer service and diagnosing of issues is the event that occurs when there is an unhandled exception. In the paradigm of web application development, you can control your hardware and rely on your application logs. But in the distributed world of mobile, the logs are all on the user's mobile device. In this scenario, it is important for you to be able to capture these problems and "phone them home" to be diagnosed/fixed (with the user's permission of course).

Your application should do the following in this situation:

  • Dump logging and state information somewhere in local storage where you can retrieve it later for diagnostics.
  • Remove any application state information that would otherwise be reloaded the next time the user opens your application. The state of the application should be assumed to be corrupt in this situation.

Unfortunately, there does not seem to be an event for this. The closest one is WinJS.Application.onerror. But, since there is no underlying way to catch an unhandled exception in the base library, I suspect there are many limitations. One scenario that I have run into is exceptions in an async event callback.

All of this being said, I believe it is important to use what you have in this situation whether it is a perfect solution or not. Therefore, I believe WinJS.Application.onerror should be handled when using WinJS.

 1 var app = WinJS.Application;
 2 app.addEventListener("error", function (args) {
 3     var msg;
 4     if(args.detail.exception) {
 5         msg = args.detail.exception;
 6     } else {
 7         msg = args.detail.errorMessage;
 8     }
 9     var locationOfError = WinJS.Navigation.location;
11     //Do something...
12 });