Windows商店应用程序中是否存在全局异常处理程序?

B. *_*non 16 c# debugging exception-handling windows-8 windows-store-apps

对于未处理的异常,至少,我希望能够捕获详细信息并将其写入文件,以便进行后续的"调试取证".Windows商店应用程序中没有"OnTerminating"事件; 有没有合适的地方/方式来完成这样的?

UPDATE

请参阅下面的评论.这是一个不适合下面的补充:

即使在删除xaml片段时,我仍然得到错误的消息,甚至在清理和重建之后... ??? 2点击错误信息只需将我带到App.xaml的顶部,现在全部是:

<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>
Run Code Online (Sandbox Code Playgroud)

更新2

关闭App.xaml并重建后,一切都很好...... ??? 哦,好吧 - 我想,一切都很好.

更新3

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

    // 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();
    }
}
Run Code Online (Sandbox Code Playgroud)

Jim*_*eil 8

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

对于基于XAML的应用程序,您可以使用UnhandledException ; 但是,它只捕获通过XAML(UI)框架出现的异常,并且您并不总是获得有关根本原因的大量信息,即使在InnerException中也是如此.

Windows 8.1更新: UnhandledException还将捕获async void方法创建的异常.在Windows 8中,此类异常只会使应用程序崩溃.LunarFrog 在他们的网站上对此进行了很好的讨论.

  • 将代码中的异常添加到App.xaml.cs中的App()构造函数中:this.UnhandledException + = <按Tab键两次以生成处理程序> (2认同)