0

I am writing a Windows Phone 8.1 app. I included UnhandledException function(event handler) in App.xaml.cs(this was suggested to me here).

Now I am running the app in an emulator. When an exception occurs, the event handler(UnhandledException function) is getting called. I have included a breakpoint in this function and from there, I go ahead in a step-over manner(Visual Studio 2013 terminology). But, always before I reach the end of the function, the debugging stops automatically. This happens at no fixed line in the function.

Can anyone help me figure out what is happening?

UPDATE: The following is the code for the handler function

 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("");
            }

        }
Cœur
  • 37,241
  • 25
  • 195
  • 267
AvinashK
  • 3,309
  • 8
  • 43
  • 94

0 Answers0