kai chen
kai chen

Reputation: 368

How to intercept and handle all exception of Windows phone Application?

We did't have any Test team support for our Product Development. so. we need intercept and handle all Exception for improve User experience. is There have any Soluction in windows phone Application?

as Fllow in app.xaml.cs file. we found :

      // Code to execute on Unhandled Exceptions
    private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
    {
        if (e.ExceptionObject is QuitException)
            return;

        if (System.Diagnostics.Debugger.IsAttached)
           {
              // An unhandled exception has occurred; break into the debugger
              System.Diagnostics.Debugger.Break();
           }


        if (System.Diagnostics.Debugger.IsAttached)
        {
            // An unhandled exception has occurred; break into the debugger
            System.Diagnostics.Debugger.Break();
        }
    }

Upvotes: 0

Views: 1349

Answers (2)

Zia Ur Rahman
Zia Ur Rahman

Reputation: 1880

Put your code in Try-Catch Block. I was also facing such problem, but then handled by Exception Handling Method.

 try
  {
   // your code
  }

 catch (Exception ex)
  {

    throw (ex);
  }

Upvotes: 0

Igor Ralic
Igor Ralic

Reputation: 15006

Yes, this should catch all the exceptions that you missed in your app. Considering that you obviously are not catching many exception somewhere else and are looking for a simple solution, this event handler might work, but I seriously don't recommend it.

This event handler catches the exceptions and then should crash/quit your app. If you handled your exceptions only here, this would lead to a huge crash count. Sometimes exceptions happen, but the app can continue working normally. That's why I recommend that you handle them as they happen in your code, and not here. That way you have a full control of how your app continues and if it continues at all, and reduce the number of "unhandled exceptions" and app crashes.

Upvotes: 1

Related Questions