Windows Store应用程序中是否有全局异常处理程序? [英] Is there a global exception handler in Windows store apps?

查看:139
本文介绍了Windows Store应用程序中是否有全局异常处理程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于未处理的异常,至少,我想能够捕获细节,并将其写入文件以进行潜在的后续调试取证。 Windows Store应用程序中没有OnTerminating事件;有没有一个合适的地方/方法来完成这样的工作?



更新



以下是一个不适合的补充:



即使删除xaml代码段,我仍然会得到这个错误,甚至在清理和重建...之后? ?? 2点击错误msg只需要我到App.xaml的顶部,现在的全部是:

 应用程序
x:Class =SpaceOverlays.App
xmlns =http://schemas.microsoft.com/winfx/2006/xaml/presentation
xmlns:x =http:/ /schemas.microsoft.com/winfx/2006/xaml
xmlns:local =using:SpaceOverlays>

< Application.Resources>
< ResourceDictionary>
< ResourceDictionary.MergedDictionaries>

<! -
定义平台外观的共同方面的样式
Visual Studio项目和项目模板需要
- >
< ResourceDictionary Source =Common / StandardStyles.xaml/>
< /ResourceDictionary.MergedDictionaries>

< / ResourceDictionary>
< /Application.Resources>



更新2



关闭应用后。 xaml和重建,一切都很好... ???哦,好的 - 一切都很好,结果好,我猜。$ /

更新3



有趣的是Windows Phone应用程序App.xaml.cs默认情况下具有此处理程序:

  //未捕获异常的全局处理程序。 
UnhandledException + = Application_UnhandledException;

private void Application_UnhandledException(object sender,ApplicationUnhandledExceptionEventArgs e)
{
if(Debugger.IsAttached)
{
//发生未处理的异常;打破调试器
Debugger.Break();
}
}


解决方案

HTML5 / JavaScript应用程序,您将 onerror 事件作为您的最后的机会捕获信息。



对于基于XAML的应用,您可以使用 UnhandledException ;但是,只捕获通过XAML(UI)框架出现的异常,即使在InnerException中,并不总是得到很多有关根本原因的信息。



Windows 8.1更新: UnhandledException 还将捕获由 async void 方法创建的异常。在Windows 8中,这样的异常会使应用程序崩溃。 LunarFrog在他们的网站上有一个很好的讨论


For unhandled exceptions, at least, I'd like to be able to catch the details and write them out to a file for potential subsequent "debugging forensics." There is no "OnTerminating" event in Windows store apps; is there a suitable place/way to accomplish such?

UPDATE

See my comment below. Here is an addition that won't fit below:

Even when removing the xaml snippet, I still get that err msg, and even after Cleaning and Rebuilding...??? 2-clicking the err msg just takes me to the top of App.xaml, the entirety of which is now:

<Application
    x:Class="SpaceOverlays.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:SpaceOverlays">

    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>

                <!-- 
                    Styles that define common aspects of the platform look and feel
                    Required by Visual Studio project and item templates
                 -->
                <ResourceDictionary Source="Common/StandardStyles.xaml"/>
            </ResourceDictionary.MergedDictionaries>

        </ResourceDictionary>
    </Application.Resources>

UPDATE 2

After closing App.xaml and rebuilding, all is well...??? Oh, well - all's well that ends well, I guess.

UPDATE 3

It's interesting that Windows Phone apps App.xaml.cs have this handler by default:

    // Global handler for uncaught exceptions.
    UnhandledException += Application_UnhandledException;

private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{
    if (Debugger.IsAttached)
    {
        // An unhandled exception has occurred; break into the debugger
        Debugger.Break();
    }
}

解决方案

For HTML5/JavaScript apps you have the onerror event as your last chance to capture info.

For XAML-based apps, you can use UnhandledException; however, that only captures exceptions that come up through the XAML (UI) framework and you don't always get a lot of information about what the root cause is, even in InnerException.

Update for Windows 8.1: UnhandledException also will capture exceptions that are created by an async void method. In Windows 8, such exceptions would just crash the app. LunarFrog has a good discussion of this on their website.

这篇关于Windows Store应用程序中是否有全局异常处理程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆