0

我们订阅了未处理的线程异常和未处理的异常,如下所示

public partial class ICEView : Form
{

    public ICEView()
    {
        InitializeComponent();

        AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(OnUnhandledException);
        Application.ThreadException += new ThreadExceptionEventHandler(OnThreadException);
    }
}

有时应用程序在没有进入异常处理程序的情况下崩溃,显示错误消息,如下面的链接所示。但是我们得到的错误信息没有“调试”按钮。显示消息框的原因可能是什么。

http://www.computerhope.com/issues/pictures/winerror.jpg

4

1 回答 1

2

尝试在Main表单之前的 Program.cs 中的方法中添加异常处理程序,或尝试在InitializeComponent方法之前添加异常处理程序。

[STAThread]
static void Main()
{
    Application.ThreadException += new ThreadExceptionEventHandler(OnThreadException);
    Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
    AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(OnUnhandledException);

    Application.Run(new ICEView());
}
于 2012-05-14T09:10:10.723 回答