Question

We've developed a .NET 3.5 CF Application and we're experiencing some application crashes due to unhandled exceptions, thrown in some lib code.

The application terminates and the standard application popup exception message box is shown.

Is there a way to catch all unhandled exceptions? Or at least, catch the text from the message box. Most of our customers simply restart the device, so that we're not able to have a look on the exception message box.

Any ideas?

Was it helpful?

Solution

Have you added an UnhandledException event handler?

[MTAThread]
static void Main(string[] args)
{
    AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;

    // start your app logic, etc
    ...
}

static void OnUnhandledException(object sender, UnhandledExceptionEventArgs e)
{
    var exception = (Exception)e.ExceptionObject;

    // do something with the info here - log to a file or whatever
    MessageBox.Show(exception.Message);
}

OTHER TIPS

I do something similar to what ctacke does.

private static Form1 objForm;

[MTAThread]
static void Main(string[] args)
{
  objForm = new Form1();
  try
  {
    Application.Run(objForm);
  } catch (Exception err) {
    // do something with the info here - log to a file or whatever
    MessageBox.Show(err.Message);
    if ((objForm != null) && !objForm.IsDisposed)
    {
      // do some clean-up of your code
      // (i.e. enable MS_SIPBUTTON) before application exits.
    }
  }
}

Perhaps he can comment on whether my technique is good or bad.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top