2

I have a blank Windows Forms Application project with the Form.Load eventhandler bound:

private void Form1_Load(object sender, EventArgs e)
{
    throw new Exception();
}

I have the proper(?) debugging settings: checked all user-unhandled exceptions to break. Yet still VS doesn't break on the line where the exception is thrown.

Is it handled by the Windows Forms API? And if yes, why is it so, doesn't it make debugging difficult?

icguy
  • 560
  • 4
  • 14
  • 5
    This is a known quirk of x64 forms. Windows swallows it. http://stackoverflow.com/questions/3209706/why-the-form-load-cant-catch-exception – vcsjones Dec 31 '14 at 14:00
  • @vcsjones -- yes, but it should at least *break* on the exception if he has the right debug settings configured, as stated. I've replicated the scenario (x64 machine, x32 process) and it's still breaking even though it's subsequently swallowed. – rory.ap Dec 31 '14 at 14:02
  • You can break at *all* exceptions, even the handled ones. Does that help? – Jeppe Stig Nielsen Dec 31 '14 at 14:06
  • Known bug, see this SO question ; http://stackoverflow.com/questions/3209706/why-the-form-load-cant-catch-exception – husnain_sys Dec 31 '14 at 14:06
  • @roryap try x64 process (uncheck "Prefer 32-bit"). Visual Studio won't break on the exception, but it will break on breakpoints. – vcsjones Dec 31 '14 at 14:07
  • @icguy -- Are you sure the load event is actually firing? What if you put a break point in that method. There's evidence that sometimes it doesn't fire (see [this](http://stackoverflow.com/questions/26166074/winforms-usercontrol-load-event-not-fired) and [this](http://stackoverflow.com/questions/9291642/some-form-events-load-shown-stopped-working), e.g.), which I seem to recall has happened to me in the past, too. – rory.ap Dec 31 '14 at 14:08
  • @vcsjones -- still breaks. – rory.ap Dec 31 '14 at 14:09
  • @vcsjones -- VS2010? SP1 installed? – rory.ap Dec 31 '14 at 14:10
  • @roryap 2013 with Update 4. – vcsjones Dec 31 '14 at 14:10
  • 1
    @JeppeStigNielsen Yes, i know, I'm just wondering why this happens. I was testing some code in that eventhandler and wondered why I didn't hit any breakpoints. Well, because execution didn't even got there but I still had the form appearing. – icguy Dec 31 '14 at 14:10
  • @roryap Yep, event firing – icguy Dec 31 '14 at 14:11
  • Check out this post about exception handling; http://www.codeproject.com/Articles/2949/Managing-Unhandled-Exceptions-in-NET. Add exception handling code in Program.cs and it will break on exception – husnain_sys Dec 31 '14 at 14:11
  • I ran into this once. I think I fixed it by setting a timer in Form Load and then in the timer event I put the code I wanted to run on Form Load. – Slapout Dec 31 '14 at 14:18

0 Answers0