读书人

请教这种状态下为什么东东会被忽略

发布时间: 2013-03-26 09:54:33 作者: rapoo

请问这种状态下为什么错误会被忽略
vs2012 vb中新建一个默认的windows窗体应用程序,在其默认的form1中这样写
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim a As Integer, b As Integer
b = 0
a = 123 / b

MsgBox("1")
End Sub
End Class



按道理来说,应该是弹出除数为0的提示,但结果是这个错误连同其之后的代码都直接被忽略,
也就是说其实只执行到b = 0这一句代码,然后就去显示窗体了

请问是何原因?

[解决办法]
load,paint等事件如果出现错误就停止执行,是不会报错的。
或者你手动写try catch
try
{
int b = 0;
int a = 2 / b;
}
catch
{
MessageBox.Show("a");
}
[解决办法]
This is a known issue on 64-bit OS platform. The reason is that the 64bit OS core does not allow user mode exception through kernal mode stacks. The exception is swallowed by OS sliently. That happens in FormLoad handler, because it is called in an OS callback. 32bits OS doesn't do this, so it doesn't repro there.

The OS team is investigating related issues. In the mean time, you do have to work around this issue. Turning on "Stop on first chance exception" will make the debugger to stop in this scenario. But it does make the debugger to stop very often, so you might want to do this only when you find a problem.

来自:

http://stackoverflow.com/questions/1583351/silent-failures-in-c-seemingly-unhandled-exceptions-that-does-not-crash-the-pr

指向msdn的链接已经没有了。

读书人网 >VB Dotnet

热点推荐