如何在WPF中显示未处理异常的堆栈跟踪报告

时间:2013-12-10 11:05:08

标签: c# wpf error-handling stack-trace

我使用此EventHandler来捕获所有未处理的异常。

 public App()
        : base()
    {
        this.Dispatcher.UnhandledException += OnDispatcherUnhandledException;
    }

  void OnDispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
    {
        ...
    }

我想显示该示例的堆栈跟踪(错误消息除外),如下图所示: enter image description here

我该怎么做?

1 个答案:

答案 0 :(得分:4)

我可能没有理解这个问题,因为根据我的理解,这似乎是一个非常简单的问题。 StackTrace类上有Exception个属性。您可以从该属性获取堆栈跟踪:

private void OnDispatcherUnhandledException(object sender, 
System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
    string stackTrace = e.Exception.StackTrace;
}

您可以在MSDN上的Exception class页面上找到更多信息。如果我误解了你的问题,请告诉我。