We have error handling around our Windows Mobile application similar to the following:
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[MTAThread]
static void Main()
{
try
{
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(OnUnhandledException);
LogWriter.WriteDebugLog("******* Application Start *******");
Application.Run(new Form1());
}
catch (Exception ex)
{
LogWriter.WriteDebugLog("LOG MAIN: " + ex.Message + "\r\nTrace: " + ex.StackTrace);
MessageBox.Show("An unexpected error has occured, please try again. If the problem continues please contact application provider.", "Fatal Error");
}
finally
{
AppDomain.CurrentDomain.UnhandledException -= new UnhandledExceptionEventHandler(OnUnhandledException);
try
{
//System.Diagnostics.Process proc = System.Diagnostics.Process.GetCurrentProcess();
//proc.Kill();
}
catch { }
LogWriter.WriteDebugLog("******* Application Exit *******");
}
}
public static void OnUnhandledException(object sender, UnhandledExceptionEventArgs e)
{
string application_name = sender.ToString();
Exception except = (Exception)e.ExceptionObject;
string errormessage = "Application " + application_name + " [ Exception " + except.Message + " ]" + Environment.NewLine + except.StackTrace;
//MessageBox.Show(errormessage, "Fatal Error");
LogWriter.WriteDebugLog(errormessage);
AppDomain.CurrentDomain.UnhandledException -= new UnhandledExceptionEventHandler(OnUnhandledException);
}
}
Despite this error handling methodology, we have received logs from users where the application has simply terminated without recording an exit or an unhandled exception or a LOG MAIN exception.
I have been trying to reproduce this by creating a very simple application and throwing around various types of exception strategy to kill the application, but with no success. Every time I throw any kind of exception it seems to be caught by the code above.
If anyone has any ideas as to what kind of issues might skip this error handling it would be greatly appreciated as this might move our investigations forwards.
Kind regards, Graham.
Edit: Slightly more information in case it is relevant as requested.
The applications in question are a large variety of Windows Mobile 6.5 applications, mostly running on Motorola MC65 devices although some are on Psion EP10 devices and some are on other devices too (so it is unlikely to be device-specific).
The applications all use SQLCe and Merge Replication. Many of them use third-party controls for displaying on forms. All of them use a certain amount of PInvoking for varying purposes.
The crashes themselves do not appear to be happening at any particular point in the application and not very often even then but when we review the logs we see the application logging its progress (including memory usage and various other useful details) and then it simply terminates without any record.