UnhandledException函数geting在中途终止

时间:2014-05-28 07:19:56

标签: c# windows-phone unhandled-exception

我正在写Windows Phone 8.1 app。我在UnhandledException中添加了App.xaml.cs函数(事件处理程序)(这是​​向我建议的here)。

现在我在模拟器中运行应用程序。发生异常时,将调用事件处理程序(UnhandledException函数)。我有在此函数中包含断点,从那里开始,我以step-over方式继续( Visual Studio 2013术语)。但是,总是在我到达函数结束之前,调试会自动停止。这发生在函数中没有固定的行。

任何人都可以帮我弄清楚发生了什么吗?

更新 以下是处理函数的代码

 private async void CurrentOnUnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            if(e.Exception.Message!=null)
            Debug.WriteLine("Exception Message" + e.Exception.Message);
            if (e.Exception != null)
            Debug.WriteLine("HRESULT CODE-  " + e.Exception.ToString());

            if (e.Exception.Data != null)
            {
                Debug.WriteLine("DATA-  "+e.Exception.Data.ToString()+" "+e.Exception.Data.Count);
                foreach(var mem in e.Exception.Data)
                {
                    Debug.WriteLine("DATA- "+mem.ToString());
                }
            }

            if (e.Exception.HelpLink != null)
            Debug.WriteLine("Help Link-  " + e.Exception.HelpLink.ToString());

            if (e.Exception.Message != null)
            Debug.WriteLine("Message-  " + e.Exception.Message);

            if (e.Exception.Source != null)
            Debug.WriteLine("Exception Source-  " + e.Exception.Source);

            if (e.Exception.StackTrace != null)
            Debug.WriteLine("Stack Trace-  " + e.Exception.StackTrace);

            if(e.Exception.InnerException!=null && e.Exception.InnerException.Source!=null)
            Debug.WriteLine("InnerException Source-  " + e.Exception.InnerException.Source);

            if (e.Message != null)
                Debug.WriteLine("Original-  "+ e.Message);


            StorageFolder documentsFolder = ApplicationData.Current.LocalFolder;
            StorageFile sampleFile = await documentsFolder.CreateFileAsync("log.txt", CreationCollisionOption.OpenIfExists);


            Debug.WriteLine("REACHED HERE");
            string text = await FileIO.ReadTextAsync(sampleFile);
            if (text != null)
                Debug.WriteLine(text);


            if(sampleFile!=null)
            {
                List<string> crashReport = new List<string>();
                crashReport.Add(" ");
                crashReport.Add("**********************************************************************************************************************************************");
                if (e.Exception != null)
                crashReport.Add("HRESULT CODE-  " + e.Exception.ToString());
                if (e.Exception.Data != null)
                crashReport.Add("DATA-  " + e.Exception.Data.ToString());
                if (e.Exception.HelpLink != null)
                crashReport.Add("Help Link-  " + e.Exception.HelpLink.ToString());
                if (e.Exception.Message != null)
                crashReport.Add("Message-  " + e.Exception.Message);
                if (e.Exception.Source != null)
                crashReport.Add("Exception Source-  " + e.Exception.Source);
                if (e.Exception.StackTrace != null)
                crashReport.Add("Stack Trace-  " + e.Exception.StackTrace);
                if (e.Exception.InnerException != null && e.Exception.InnerException.Source != null)
                crashReport.Add("InnerException Source-  " + e.Exception.InnerException.Source);
                if (e.Exception.InnerException != null && e.Exception.InnerException.Message != null)
                crashReport.Add("InnerException Message-  " + e.Exception.InnerException.Message);
                if (e.Exception.InnerException != null && e.Exception.InnerException.StackTrace != null)
                crashReport.Add("InnerException StackTrace-  " + e.Exception.InnerException.StackTrace);
                if(e.Message!=null)
                crashReport.Add("Original Unhandled Exception Message-  " + e.Message);

                //Debug.WriteLine("Exception Message"+e.Exception.Message);
                await FileIO.AppendLinesAsync(sampleFile, crashReport);

        }

            sampleFile = await documentsFolder.GetFileAsync(crashLog);
            if(sampleFile!=null)
            {
                string texty = await FileIO.ReadTextAsync(sampleFile);
                Debug.WriteLine(texty);
                Debug.WriteLine("");
            }

        }

0 个答案:

没有答案