![]() But only if you debug, it will not work without one and won't work on the user's machine. So special rule, if a debugger is attached then the dispatcher loop won't catch the exception and raise the event. The debugger would have no reason to step in and show you how the code bombed since the exception is actually handled. That behavior seriously gets in the way of debugging code that is still unstable. ![]() It becomes modal like that by starting another dispatcher loop, the exact equivalent to Application.Run().Įxceptions raised by code that is activated by the dispatcher loop (event handlers) are reported through the Application.UnhandledException event. ShowDialog() is special, that method does not return until you close the dialog. That is done to help you debug unhandled exceptions. MessageBoxButtons.OK, MessageBoxIcon.Information MessageBox.Show(this, ex.Message, "Exception Caught!", Private void OnMouseClick(object sender, MouseEventArgs e) / The main entry point for the application.Īpplication.SetCompatibleTextRenderingDefault(false) The following code is sufficient to demonstrate the issue. Why can I catch the Exception in Form1 when running under the debugger? Or, more to the point, Why does the presence of the Debugger change the exception-throwing behaviour of "ShowDialog"? If I didn't launch the program without the debugger attached, even if I attach the debugger later, I cannot catch the Exception from Form1 (this is more the behaviour I expect). ![]() If I ran this program from the Visual Studio debugger, I can catch this Exception at the call site in Form1 (which I did not expect!). Form2 throws an Exception on the GUI thread. Consider this: Form1 launches Form2 as a modal dialog with a call to ".ShowDialog".
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |