问题描述
对于未处理的异常,至少,我希望能够捕获详细信息并将它们写到文件中,以供可能的后续调试取证".Windows 商店应用程序中没有OnTerminating"事件;有没有合适的地方/方式来完成这个?
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?
请参阅下面的评论.这是一个不适合下面的补充:
See my comment below. Here is an addition that won't fit below:
即使在删除 xaml 片段时,我仍然会收到错误消息,即使在清理和重建之后......?2-clicking err msg 将我带到 App.xaml 的顶部,现在的全部内容是:
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>
更新 2
关闭 App.xaml 并重建后,一切都很好......???哦,好吧——我想一切都很好,结局很好.
UPDATE 2
After closing App.xaml and rebuilding, all is well...??? Oh, well - all's well that ends well, I guess.
有趣的是,Windows Phone 应用 App.xaml.cs 默认有这个处理程序:
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();
}
}
推荐答案
对于 HTML5/JavaScript 应用程序,您有 onerror 事件是您获取信息的最后机会.
For HTML5/JavaScript apps you have the onerror event as your last chance to capture info.
对于基于 XAML 的应用,您可以使用 UnhandledException;但是,这仅捕获通过 XAML (UI) 框架出现的异常,即使在 InnerException 中,您也不总是能获得很多关于根本原因的信息.
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.
Windows 8.1 更新: UnhandledException 还将捕获由 async void
方法创建的异常.在 Windows 8 中,此类异常只会使应用程序崩溃.LunarFrog 在他们的网站上有一个很好的讨论.
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 商店应用程序中是否有全局异常处理程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!