我怎样才能得到“;[MyApp]遇到问题,需要关闭“;已处理AppDomain.UnhandledException的消

本文关键字:UnhandledException 的消 AppDomain 处理 问题 MyApp 遇到 | 更新日期: 2023-09-27 18:23:52

我收到用户收到Windows XP错误消息"[My Application]遇到错误,需要关闭"的报告。此消息表示我的应用程序中存在未处理的异常,对吗?我有AppDomain.未处理的异常,可以处理代码中任何未捕获的异常,所以我不确定用户是如何收到这个错误的。一个类似问题的答案表明,是单独的线程导致了这种情况,但这些线程仍然在同一应用程序域中运行,因此它们会被处理,不是吗?这是我的处理代码,以防你发现它正在抛出异常的地方:

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
    }

我怎样才能得到“;[MyApp]遇到问题,需要关闭“;已处理AppDomain.UnhandledException的消

如果你的应用程序做了一些非常糟糕的事情(例如错误的互操作导致内存损坏),那么你不会看到异常。你的申请会失败的。

内存不足等稍微不那么可怕的事情也会导致应用程序在不运行异常处理程序的情况下失败。

这个问题及其答案讨论了捕捉所有异常的不可能。

相关文章:
  • 没有找到相关文章