Why Form_Load event already catches all the Exceptions?
Ive put my initialization code at form load, since it is not a good idea to leave it at the constructor because the designer can crash.
The problem is that Ive just realized that any exception inside the form load event will be catch internally!
Why? How should I overcome that?
private void Form1_Load(object sender, EventArgs e)
{
//This exce开发者_如何学Cption will be catch internally (I don't know why and where)
throw new Exception("test");
}
It is a bug and is explained here:
The case of the disappearing OnLoad exception – user-mode callback exceptions in x64
http://blog.paulbetts.org/index.php/2010/07/20/the-case-of-the-disappearing-onload-exception-user-mode-callback-exceptions-in-x64/
VS team answer: From here: https://connect.microsoft.com/VisualStudio/feedback/details/357311/silent-exceptions-on-x64-development-machines
Posted by Microsoft @ 22/04/2010 17:12 Hello,
This bug was closed as "External" because this behavior results from how x64 version of Windows handle exceptions. When a user mode exception crosses a kernel transition, x64 versions of Windows do not allow the exception to propagate. Therefore attached debuggers are unaware of the fact that an exception occurred resulting in the debugger failing to break on the unhandled exception.
Unfortunately where is nothing that the Visual Studio team can do to address this, it is the result of operating system design. All feedback regarding this issue should be addressed to the Windows team; however the Windows team considers this to be the "correct" operating system design, and considers the x86 behavior to be "incorrect".
Best Regards, Visual Studio Debugger
Solution that Im using: Ive put the code that was inside the form load to the constructor and I check if the app is running in designer or not
protected static bool IsInDesigner
{
get { return (Assembly.GetEntryAssembly() == null); }
}
if (!MainForm.IsInDesigner)
LoadControl();
精彩评论