【问题标题】:WinRt. UnhandledException handler. StackTrace is nullWinRt。 UnhandledException 处理程序。 StackTrace 为空
【发布时间】:2013-05-31 22:32:43
【问题描述】:

我在 WinForms 上有一个项目,代码如下:

AppDomain.CurrentDomain.UnhandledException += CurrentDomainUnhandledException;

private void CurrentDomainUnhandledException(object sender, UnhandledExceptionEventArgs e)
{            }

e.ExceptionObject 包含完整的 StackTrace。

在 Win Store 项目中:

this.UnhandledException += (s, e) =>{                                               
{                                              
    MarkedUp.AnalyticClient.LogLastChanceException(e);
};

e.Exception.StackTrace 为空。

这两个异常都是由这段代码产生的:

int a=0;
....

try
{
    int i = 1 / a;
}
catch (Exception exp)
{
    throw;
}

有什么想法吗?

【问题讨论】:

    标签: windows-runtime windows-store-apps windows-store


    【解决方案1】:

    MSDN 上的参考表明这是一个限制:http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.application.unhandledexception

    一个显着的限制是 UnhandledException 事件参数不包含从应用程序代码传播的原始异常那么多的详细信息。只要有可能,如果应用程序需要对某个异常进行特定处理,最好在异常传播时捕获它,因为届时会有更多详细信息可用。 UnhandledException 事件参数通过 Exception 属性公开一个异常对象。但是,不能保证此异常对象的类型、消息和堆栈跟踪与引发的原始异常相匹配。事件参数确实公开了 Message 属性。在大多数情况下,这将包含最初引发的异常的消息。

    【讨论】:

      【解决方案2】:

      您是否在调试模式下运行解决方案?当您在调试模式下运行解决方案时,App.g.i.cs 文件中似乎发生了一些事情。当我在发布模式下运行您的示例时,堆栈跟踪在 UnhandledException 事件中可用。

      在我的测试解决方案中,它首先在这里中断:

      #if DEBUG && !DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
                  UnhandledException += (sender, e) =>
                  {
                      if (global::System.Diagnostics.Debugger.IsAttached) global::System.Diagnostics.Debugger.Break();
                  };
      #endif
      

      然后它转到我在 app.xaml.cs 文件中定义的 UnhandledException 处理程序。在 Debug 中,stacktrace 消失了,在 Release 模式下,stacktrace 和异常详细信息都在那里。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2010-09-08
        • 1970-01-01
        • 2018-06-12
        • 1970-01-01
        • 1970-01-01
        • 2010-11-27
        • 2019-05-01
        • 2012-09-02
        相关资源
        最近更新 更多