WP7 Error Reporting done simply
Part 3 in my series of blog posts covering the quick code Tips & Tricks I shared at UK Tech.Days, is about enabling your users to provide you with some useful information if things go badly with your Windows Phone 7 app.
Often on the marketplace I have seen apps that have multiple reviews by different users just saying things like "Crashes on startup!" or "Doesn't work on my device!", and as a developer I know its frustrating to see things like this when the app is working perfectly fine on your phone. While it would be nice for users to provide detailed repro' steps and associated data, that's not really likely to happen, but in my opinion the main thing you want as a developer is the Exception and a Call Stack of whatever is causing the app to crash.
Luckily, the App.xaml.cs file included in the standard Windows Phone project template includes a function named "Application_UnhandledException" which is called when an unhandled exception occurs and is the last point of call before the app closes and returns the user to the homescreen. This function is primarily used to allow the debugger to break into the app when debugging so that the developer can try to investigate the unhandled exception, however by adding a little bit of code to it you can provide users in the wild the ability to email the exception information to you.
The following code shows this function with the added 'else' block which asks the user if they would like to send the error details to the developer. If they accept then a new email task is created which contains the exception object information (the exception message and call stack). Clearly if you want to include more information then you can just add it to the body of the email:
private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e) { if (System.Diagnostics.Debugger.IsAttached) { // An unhandled exception has occurred; break into the debugger System.Diagnostics.Debugger.Break(); } #region Error Reporting code else { var result = MessageBox.Show("Would you like to email the details of this error to the Developer?\n\n(No personal information, other than your email address, will be sent to the Developer)", "An error has occurred!", MessageBoxButton.OKCancel); if (result == MessageBoxResult.OK) { var task = new EmailComposeTask(); task.To = "contact@DeveloperEmailAddress.com"; task.Subject = "Error Report: TechDays 2011 App"; task.Body = String.Format("An unhandled exception occurred in TechDays 2011 App:\n\n{0}", e.ExceptionObject.ToString()); task.Show(); } } #endregion }
The great things about this approach is that it can very easily be dropped into any app, requires no infrastructure/web service and as this is done via email, the user gets to clearly see and approve all information being sent. This is a good thing from a user's perspective as they can see that no personal information (other than their email) is being shared.
This post was also a guest post over at the VerySoftware Blog
Sunday, July 10, 2011 at 12:21PM
Reader Comments (1)
how about HTMLpost on a Q&A site (as stack-overflow),
makes sense to you?
a hint: you can add system info to the error post as well stack-backtrace and exception-msg-stack