2014-03-30 57 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); 

    } 
} 
相关问题