So this is a problem I've seen for some time and kind of just keep overlooking it. Thing is there are other people in the office who are coming against it as well, and they don't have as much .Net experience so depending on the debugger is big for them.
What happens is that in VB.Net when debugging code where an exception occurs, often inside a WinForms message (like the Closed event), instead of the debugger capturing it and bringing you to the line where the exception occurred. Instead the method it occurred in just exits, the entire call stack is dumped, and the program returns to the usual WinForms process pump as if idle.
If this happens in say the 'FormClosed' event, well the stacks dumps, and the form never actually closes because the code that the .Net framework does to actually close the form never executes because in my event handler for the event I happen to access an array with a bad index. (duh the fix is to not use a bad index... but that's the thing, we're debugging, we're expecting the debugger to say "HEY, RIGHT HERE DUMB ASS")
This usually isn't a huge problem for me, when I see it I know what's happening, and I just follow it on my own line by line and capture the error myself and figure it out. But this is time consuming, and not something I can easily teach to the rest of the staff.
Now this has been happening for quite some time, but I never really recorded what happened for showing an example. Today though I wrote down the chain of events that occurs to cause this. Note, I've attempted recreating this in simpler code elsewhere and couldn't get it to recreate. But it recreates over and over in the code that I found it in... so yeah, I'm just documenting this for the sake of documenting it and discussion.
When a button on a Form is pressed, Close() is called on that form.
Closing event raises, some validation occurs to make sure that we should allow closing, success.
Closed event raises and is captured by a collection in a 'FormManager' class I have. This collection listens for various events and raises another event saying that one of its members raised the Closed event. It's called 'BubbledFormClosed' and hands out args for which form was closed.
Manager listens for this bubbled event.
Manager on receiving the message finds an associated delegate that is used as a callback for when the form is closed (when you ask the FormManager to open a specific form by a String key, you can supply a callback to be called when it closes). This callback sometimes may be wrapped by another delegate for various reasons.
Manager calls the callback, passes in an object with some data about the closing form, this object is called a 'FormClosedVector'.
In this particular example the callback is in another form (the form that requested this closing form to be opened). It pulls some values out of the vector and calls a method on itself.
This method it calls accesses a Microsoft.VisualBasic.Collection object (ugh, big project being converted from VB6, working on removing all of these), the collection is looped over from 0 to Length - 1. But because Collection is a 1-based indexed object, should have been 1 to Length. IndexOutOfRangeException occurs.
Debugger doesn't catch exception, instead the method stops right there and exits, and the entire call stack for 'Close()' is dropped. If stepping through line by line, the debugger returns to where 'Close()' was called, and continues on... but the form never actually Closed.
So, what do you guys think?
This post has been edited by lordofduct: 08 October 2013 - 10:35 AM