The stack trace pointed to the AdControl which points me in the direction of that this is a Microsoft problem and not related to my source code.
Here is a breakdown on adding a catch all error handling to your windows phone app using C#.
- First create a ErrorPage.xaml page to your project.
- Add a Textblock control "ErrorText" that will store your error message:
<TextBlock x:Name="ErrorText" Style="{StaticResource PhoneTextSmallStyle}" TextWrapping="Wrap" Text="error will go here" Margin="12,20,12,0" /> - Modify the Header field and add any other elements to the page to make it user friendly:
- Now open the code behind page (ErrorPage.xaml.cs) and add the following code:
public static Exception Exception;
protected override void OnNavigatedTo(NavigationEventArgs e)
{
ErrorText.Text = Exception.Message;
} - Next add code to the App.xaml.cs file in the Application_UnhandledException procedure:
e.Handled = true;
ErrorPage.Exception = e.ExceptionObject;
(RootVisual as Microsoft.Phone.Controls.PhoneApplicationFrame).Source = new Uri("/ErrorPage.xaml", UriKind.Relative); - Add the same code to the RootFrame_NavigationFailed procedure using the e.Exception object instead of e.ExceptionObject:
e.Handled = true;
ErrorPage.Exception = e.Exception;
(RootVisual as Microsoft.Phone.Controls.PhoneApplicationFrame).Source = new Uri("/ErrorPage.xaml", UriKind.Relative);
- Next add a button and code that you know will fail. Like divide by 0 or navigate to a page that does not exists.
- I added the Report Error button that will send the Stack Trace back to me. Its probably not needed because the Stack Trace is appearing in the reports.
- The Back button will navigate the user back to the start page. The reason why to manually pushed the user is because the Back button the phone is what is causing the AdControl error. This gives a user the ability to stay in the app otherwise they would have to click the Window button then reopen the application.
No comments:
Post a Comment