2013-12-10 45 views
1

我使用此EventHandler来捕获所有未处理的异常。如何在WPF中显示未处理的异常的堆栈跟踪报告

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

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

我想在这张照片显示的exeption(除错误消息)的堆栈跟踪,如: enter image description here

我怎么能这样做?

回答

4

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

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

你可以找到从Exception class页的详细MSDN上。如果我误解了你的问题,请告诉我。

+0

它与“e.Exception.StackTrace”合作谢谢! – cheziHoyzer

+0

哦,是的,对不起,我忘了改变这个......这是复制和粘贴的问题。感谢您指出了这一点。 – Sheridan