问题
I've encountered this weird issue of silent exceptions in 64 bit. What is that cause this bahavior? I would like to understand why does this occur and what is the recommended solution?
- disappearing OnLoad exception
- microsoft - silent exception
- KB976038
on the main:
try
{
Application.Run(new Form1());
}
catch
(Exception ex)
{
MessageBox.Show("Error");
}
private void Form1_Load(object sender, EventArgs e)
{
throw new Exception("oh no!");
}
回答1:
In order to load a form, your code will call into a kernel function to create the form's window, and this kernel function will in turn call back into your code by sending a message that invokes your OnLoad
method. If you throw an exception in that method, the exception handling mechanism walks the call stack back to the kernel mode boundary.
On x86 an exception can go through this boundary and back to the original caller. On x64 it stops when it hits the boundary and cannot continue. In XP64 and Vista the exception was swallowed (ignored), while a 64-bit app with a manifest saying it is Win7-compatible will crash when this happens. To get the crashing behavior on other OSes or for 32-bit apps on 64-bit Win7, see KB976038.
This behavior will happen for any event handler that is invoked as a callback from kernel mode on x64.
来源:https://stackoverflow.com/questions/4497122/silent-exception