Error handling wp7错误处理

Error handling wp7错误处理,error-handling,windows-phone-7,Error Handling,Windows Phone 7,我的WP7应用程序中有一个ErrorPage.xaml页面。当发生未经处理的异常时,将调用app.xaml.cs中的方法,该方法将异常传递到ErrorPage.xaml.cs,并向用户显示该错误以及返回主页的链接。 如果我太快地单击AppBar图标按钮,则会引发导航失败事件,仍会调用errorpage,但错误页面上不会显示任何内容。AppBar是唯一可见的东西 不知道为什么 下面是我的app.xaml.cs中的代码 // Code to execute on Unhandled

我的WP7应用程序中有一个ErrorPage.xaml页面。当发生未经处理的异常时,将调用app.xaml.cs中的方法,该方法将异常传递到ErrorPage.xaml.cs,并向用户显示该错误以及返回主页的链接。 如果我太快地单击AppBar图标按钮,则会引发导航失败事件,仍会调用errorpage,但错误页面上不会显示任何内容。AppBar是唯一可见的东西

不知道为什么

下面是我的app.xaml.cs中的代码

        // Code to execute on Unhandled Exceptions
    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();
        }

        e.Handled = true;
        ErrorPage.Exception = e.ExceptionObject;
        (RootVisual as Microsoft.Phone.Controls.PhoneApplicationFrame).Source =
            new Uri(Navigation.PAGE_ERROR, UriKind.Relative);
    }
Error.xaml是这样的


我怀疑一旦它点击Application\u UnhandledException并将异常设置为Handled=true,如果连续两次出现,它可能会变得不稳定-解决方法是确保AppBar按钮在尝试执行某项操作时只允许按一次,以便在尝试导航时禁用,如果失败则重新启用


此外,如果您还没有这样做,请考虑使用TraceChr.NeXiTrkEk用于您的导航方法调用。

我担心的是,您正从这个错误页面导航回到主目录。这意味着您可以按back 2x,并可能返回到错误状态?WP7 training toolkit显示了一个示例,其中向用户显示了未处理异常的错误页面。我扩展了它,向用户显示了一条友好的消息,这样他们就可以转到主页并再次开始使用该应用程序。你认为通过认证有什么问题吗?@PratikKothari我在市场上有多个应用程序,你可以从错误页面返回,再次尝试上一个操作,因此它肯定通过了认证。使用Mango/WP 7.1,您还可以清除backbackback,以便按back退出您的应用程序,但这取决于您是否希望人们能够重试,或者您是否能够检测到错误是否严重,他们是否需要重新启动应用程序。
    <Grid x:Name="LayoutRoot" Background="{StaticResource GlobalPageBackgroundBrush}" CacheMode="BitmapCache">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <!--TitlePanel contains the name of the application and page title-->
    <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="24,24,0,12">
        <TextBlock x:Name="ApplicationTitle" Text="{StaticResource AppName}" Style="{StaticResource PhoneTextNormalStyle}" FontWeight="SemiBold"/>
        <TextBlock x:Name="PageTitle" Text="error" Margin="-3,-8,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
    </StackPanel>
    <!--ContentPanel - place additional content here-->
    <Grid x:Name="ContentPanel" Grid.Row="1">
        <TextBlock x:Name="ErrorText" Style="{StaticResource PhoneTextTitle3Style}" TextWrapping="Wrap" />
        <StackPanel x:Name="FriendlyErrorStackPanel" Margin="0,100,0,0" Orientation="Vertical">
            <TextBlock Style="{StaticResource PhoneTextTitle3Style}" TextWrapping="Wrap">
                <TextBlock.Text>
                   Please click the link below to return to the main page of the application.
                </TextBlock.Text>
            </TextBlock>                
            <HyperlinkButton Style="{StaticResource PhoneHyperlinkStyle}" Content="Start Over" NavigateUri="/Views/MainPage.xaml" />
        </StackPanel>
    </Grid>
</Grid>
    public partial class ErrorPage : PhoneApplicationPage
{
    public ErrorPage()
    {
        InitializeComponent();
    }

    public static Exception Exception;

    // Executes when the user navigates to this page.
    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        if (Exception != null)
        {
            if (System.Diagnostics.Debugger.IsAttached)
            {
                FriendlyErrorStackPanel.Visibility = System.Windows.Visibility.Collapsed;
                ErrorText.Text = Exception.ToString();
            }
            else
            {
                FriendlyErrorStackPanel.Visibility = System.Windows.Visibility.Visible;
                ErrorText.Text = GlobalConstants.DEFAULT_ERROR_MESSAGE;
            }
        }

        base.OnNavigatedTo(e);
    }
}