I have reports of users getting the Windows XP error "[My Application] encountered an error and needs to close" message. This message is an indication of an unhandled exception in my application right? I have AppDomain.Unhandlled exception wired up to handle any uncaught exceptions from my code so I'm not sure how users are receiving this error. An answer to a similar question said something about separate threads causing this, but those still run in the same app domain and so they would be handled wouldn't they? Here's my handling code just in case you spot a place where it is throwing an exception:
public void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
#region Global Exception Handling
string support = String.Empty;
//try to get the support information from the common project
try
{
support = Common.Constants.ErrorMessages.RETRY_OR_CONTACT_SUPPORT;
}
catch(Exception)
{
//Use hard coded support info if the common project is not accessible
support = "Please try again or contact the Support Center at 877-555-5555";
}
string message = "An error occured that OASIS was not able to recover from. " + support;
try
{
//Try to use the OasisErrorDialog to show the error. If the exception derives from Exception, use OasisErrorDialog to log it.
if (e.ExceptionObject is Exception)
OasisErrorDialog.ShowErrorDialog(message, "A Serious Error Has Occured", true, true, (Exception)e.ExceptionObject);
else
{
//The exception doesn't derive from Exception so we need to try to log it using StepUp
OasisErrorDialog.ShowErrorDialog(message, "A Serious Error Has Occured");
ExceptionHandler.HandleException("An unhandled error that does not derive from the Exception class was thrown." + e.ExceptionObject.ToString());
}
}
catch (Exception)
{
//The OasisErrorDialog wasn't available so display the error in a standard MessageBox
MessageBox.Show(message, "A Serious Error Has Occured");
try
{
//If the StepUp framework is still working, log the exception info
if (e.ExceptionObject is Exception)
ExceptionHandler.HandleException("An unhandled exception occured", (Exception)e.ExceptionObject);
else
ExceptionHandler.HandleException("An unhandled error occured: "+e.ExceptionObject.ToString());
}
catch (Exception) { }
}
#endregion
}
If your application does something really horrible (e.g. faulty interop causes memory corruption) then you won't see an exception. Your application will just fail.
Slightly less horrible things such as running out of memory can also cause your application to fail without running your exception handler.
This question and its answers discuss the impossibility of catching all exceptions.