我怎样才能得到“[MyApp]遇到问题并且需要关闭”已处理 AppDomain.UnhandledException 的消息?
我收到报告称,用户收到 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
}
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
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的应用程序做了一些非常可怕的事情(例如,错误的互操作导致内存损坏),那么您将不会看到异常。你的申请只会失败。
稍微不那么可怕的事情(例如内存不足)也可能导致应用程序在不运行异常处理程序的情况下失败。
这个问题及其答案< /a> 讨论捕获所有异常的不可能性。
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.