Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Revision as of 06:55, 26 April 2013 by hamishwillee (Talk | contribs)

Reporting unhandled exceptions in your Windows Phone apps

From Wiki
Jump to: navigation, search

While many bugs are caught during development, nothing tests an app as much as real-world testing on a deployed application. At this point it is important to be able to get debug information back from the end-user. This article collects links to other public topics on how to catch unhandled exceptions in your app, log them, and send them to the developer for analysis.

WP Metro Icon Bug.png
WP Metro Icon WP8.png
SignpostIcon WP7 70px.png
Article Metadata
Code ExampleTested with
Devices(s): WP7 Emulator
Platform(s): Windows Phone 7.5 and later
Windows Phone 8
Windows Phone 7.5
Keywords: Application_UnhandledException, Crash Log, Exception handling, Checkpoints, IsolatedStorage
Created: somnathbanik (12 Oct 2011)
Updated: influencer (26 Apr 2013)
Last edited: hamishwillee (26 Apr 2013)

Basic methods

There are two basic methods for getting information about exception conditions that occur in an app:

  • Detect when an exception occurs and save the extended error information.
    There is a method named Application_UnhandledException() in app.xaml.cs file which gets called whenever an unhandled exception gets fired. Extended exception information like the stack trace can be written to a crash log here:
    private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
    string errorString = DateTime.Now.ToLocalTime().ToString() + " | " + "Message: " + e.ExceptionObject.Message + "Stack Trace: " + e.ExceptionObject.StackTrace;
  • Log data at checkpoints in code. This allows you to verify "last good" points in your code execution and get some information about the state of the running app

Once an error log has been created, there are several ways to make this available to the developer:

  • Create a log file in isolated storage and send to a server or to a specified email address
  • Display error data in a special page in the app next time it is started

Article list

Various approaches based on the above methods are well documented on the Internet. The following articles are recommended reading:

Example code

The attached example is a modification of Listbox handling in Windows Phone 7 in which listBoxFlickerSearch_SelectionChanged() creates an unhandled exception when a user clicks on the list item. The exception is then displayed in its own view. This approach is very similar to that described in Jimmy's Blog above.

The full source code of the example is available here:

263 page views in the last 30 days.