gpt4 book ai didi

c# - 如果我不调试应用程序,则不会捕获异常

转载 作者:行者123 更新时间:2023-11-30 16:29:58 25 4
gpt4 key购买 nike

有两个DLL,A和B,在A.DLL中有一个窗体类是这样的:

namespace AAA
public class AForm: Form
{
...
private void btnOK_Click(object sender, EventArgs e)
{
DoSomeSth();
}
}

在B.DLL中,有这样一段代码

try
{
AForm dlg = new AAA.AForm();
dlg.ShowDialog();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}

点击确定按钮后DoSomeSth函数会出现异常我用vs2005调试代码时,B.DLL可以捕获到异常,但如果不调试直接运行应用程序,B.DLL中就捕获不到异常,请问是什么原因?

最佳答案

这是一个 known issue .根据知识库文章:

When you run your Windows Forms application without using the debugger, you use the NativeWindow.CallBack method to catch the exception and to prevent the program from unexpectedly quitting (crashing). In the NativeWindow.CallBack method, you populate the exception message by using a standard exception dialog box.

However, if you run your Windows Forms application with the debugger, you do not catch the exception because you use the NativeWindow.DebuggableCallBack method. When you use the NativeWindow.DebuggableCallBack method, the just-in-time (JIT) debugger stops the application from running.

关于c# - 如果我不调试应用程序,则不会捕获异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6026808/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com