我有用户收到Windows XP错误报告“[我的应用程序]遇到错误并需要关闭”消息。此消息表明我的应用程序中存在未处理的异常吗?我有AppDomain.Unhandlled异常连接来处理我的代码中的任何未捕获的异常,所以我不确定用户是如何收到此错误的。对类似问题的回答说了一些关于单独线程导致这种情况的问题,但是那些仍然在相同的应用程序域中运行,因此它们将被处理不是吗?这是我的处理代码,以防你发现它抛出异常的地方:
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
}
答案 0 :(得分:0)
如果您的应用程序执行的操作非常糟糕(例如,错误的互操作会导致内存损坏),那么您将看不到异常。您的申请将失败。
稍微不那么可怕的事情,例如内存不足也会导致应用程序失败而不运行异常处理程序。
This question and its answers讨论了捕捉所有异常的不可能性。