C# 如何知道未处理的异常发生在何处?

C# 如何知道未处理的异常发生在何处?,c#,xaml,windows-phone-8,windows-phone,C#,Xaml,Windows Phone 8,Windows Phone,当我运行应用程序时,我不断遇到以下错误: System.ArgumentException:值不在预期范围内 射程 我不知道这个错误到底发生在哪里,也不知道原因是什么。难道不可能从以下方面了解这一点: private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e) { if (Debugger.IsAttached) { //

当我运行应用程序时,我不断遇到以下错误:

System.ArgumentException:值不在预期范围内 射程

我不知道这个错误到底发生在哪里,也不知道原因是什么。难道不可能从以下方面了解这一点:

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


我如何知道未处理的异常发生在哪里?谢谢

以下代码将打印消息和堆栈跟踪。您可以从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);

    }
}