Click here to Skip to main content
15,881,767 members
Articles / Mobile Apps / Windows Phone 7

Simple Error Reporting on WP7 REDUX

Rate me:
Please Sign up or sign in to vote.
5.00/5 (3 votes)
8 Feb 2011CPOL 9K   5  
Simple Error Reporting on WP7 REDUX

“Redux is a post-positive adjective meaning "brought back, restored" (from the Latin reducere - bring back) used in literature and film titles.”

After posting my last article, I received quite a lot of comments and emails about my approach, asking questions like: Would a user of your application be happy to know that it is sending emails back to a support address?

I decided to rather tell the user that “something” went wrong and then ask them if they would like to mail a report to the application developers…

A while ago, I looked at the Coding4Fun Windows Phone Toolkit, and they had the concept of a prompt (or more specific, a PopUp). Here is my prompt/PopUp:

C#
public class ExceptionPrompt : PopUp<Exception, PopUpResult>
{
    private Button okButton;
    private CheckBox submitCheckBox;
    private Exception exception;

    public ExceptionPrompt()
    {
        DefaultStyleKey = typeof(ExceptionPrompt);
        DataContext = this;
    }

    public override void OnApplyTemplate()
    {
        base.OnApplyTemplate();

        if (okButton != null)
            okButton.Click -= okButton_Click;

        okButton = GetTemplateChild("okButton") as Button;
        submitCheckBox = GetTemplateChild("canSubmitCheckBox") as CheckBox;
            
        if (okButton != null)
            okButton.Click += okButton_Click;
    }

    public string To { get; set; }

    void okButton_Click(object sender, RoutedEventArgs e)
    {
        var message = new StringBuilder();
        message.Append("Exception type: ");
        message.Append(exception.GetType());
        message.Append(Environment.NewLine);
        message.Append("Message: ");
        message.Append(exception.Message);
        message.Append(Environment.NewLine);
        message.Append("Stack trace: ");
        message.Append(exception.StackTrace);
        message.ToString();

        var task = new Microsoft.Phone.Tasks.EmailComposeTask 
	{ Body = message.ToString(), Subject = "Error Report", To = To };

        if (submitCheckBox.IsChecked == true)
        {
            task.Show();          
        }

        OnCompleted(new PopUpEventArgs<Exception, PopUpResult> 
		{ PopUpResult = PopUpResult.OK });    
    }
        
    public void Show(Exception exception)
    {
        this.exception = exception; 

        base.Show();
    }
}

Now, once the exception has occurred, we just call the following code!

C#
var exception = new ExceptionPrompt();
exception.Show(new SecurityException("Ooops, something is seriously wrong!!!"));

The user can then opt-in to send the exception to the application developers!

User now has the choice if she/he wants to send the developer the error report!

Here is the code.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
South Africa South Africa
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --