我有用户获取Windows XP错误报告“[我的应用程序]遇到错误,需要关闭”消息。此消息表明我的应用程序中存在未处理的异常?我有AppDomain.Unhandlled异常连接起来处理我的代码中的任何未捕获的异常,所以我不知道用户如何收到此错误。对类似问题的回答说了一些有关单独线程的原因,但这些线程仍然运行在同一个应用程序域中,因此它们将被处理吗?这里是我的处理代码,以防万一你发现一个地方,它抛出一个异常:我怎样才能得到“[MyApp]遇到问题,需要关闭”消息与AppDomain.UnhandledException处理?
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
}
嗯,代码不会调用Environment.Exit(),所以这是正常的。 – 2012-04-04 17:41:25
Environment.Exit()在这种情况下通常会被调用吗?我认为捕捉例外会阻止它进一步提升。虽然我确实打算让应用程序停止运行。 – xr280xr 2012-04-11 18:58:53