2014-03-30 106 views
0

當我運行應用程序時,我不斷收到此錯誤:如何知道未處理的異常發生在哪裏?

System.ArgumentException: Value does not fall within the expected range.

我不知道在哪裏出現此錯誤或確切的原因是什麼。難道不知道:

private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e) 
{ 
    if (Debugger.IsAttached) 
    { 
     // An unhandled exception has occurred; break into the debugger 
     Debugger.Break(); 
    } 
} 

in App.xaml

我怎麼知道未處理的異常發生在哪裏?謝謝

回答

0

以下代碼將打印消息和堆棧跟蹤。你可以從stackTrace中得到發生異常的地方。

private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e) 
{ 
    if (Debugger.IsAttached) 
    { 
     MessageBox.Show(e.ExceptionObject.Message + "\r\n" + e.ExceptionObject.StackTrace, "Error", MessageBoxButton.OK); 

    } 
} 
相關問題