0

I have a Form that has an event handler attached to the Resize event. When the event is called there is logic to reposition some controls, but that logic throws an exception.

Here is some code that reproduces the problem (within the form.designer.cs file):

this.Resize += OnResize;

...

private void OnResize(Object sender, EventArgs eventArgs)
{
    throw new Exception();
}

On some machines when this is run within Visual Studio the exception causes an exception dialog to be displayed, but on others there is nothing, although there is an entry for the First Time Exception in the output window.

I've checked the exceptions dialog and the 'user-unhandled' option for the specific exception is checked in both cases. It's like the UI framework absorbs the problem in some cases and not others, which must be a system setting I guess, but which? Any clues?

TheLethalCoder
  • 6,668
  • 6
  • 34
  • 69
LordWilmore
  • 2,829
  • 2
  • 25
  • 30
  • 1
    Show us some code, we are not mind readers – TheLethalCoder Nov 17 '16 at 10:52
  • @TheLethalCoder I think it's fairly self-explanatory. myform.Resize += myresizehandler. private void myresizehandler(...) { throw new exception; }. In some cases I get an exception dialog raised, in others I don't. – LordWilmore Nov 17 '16 at 10:55
  • Is one machine 32-bit and the other 64-bit? – TheLethalCoder Nov 17 '16 at 11:07
  • 2
    It is certainly possible, particularly so on Win7. Happens when you disable the backstop in the dispatcher loop that causes the Application.ThreadException event to be raised. Microsoft had a great deal of trouble dealing with unhandled exceptions in 32-bit code that runs in the Wow64 emulator for events that start life in the 64-bit window manager. On Win7 that can trigger the "Application Compatibility Assistant" which offers to keep the program compatible. Everybody clicks Yes, they'll never see the exception again. I'll stop guessing now. – Hans Passant Nov 17 '16 at 11:08
  • @HansPassant Are you describing your answer here: http://stackoverflow.com/a/4934010/4631427 – TheLethalCoder Nov 17 '16 at 11:10

1 Answers1

0

You could register the AppDomain.CurrentDomain.UnhandledException event. This will allow to capture and log such errors when they happen so you can look at it further.

John
  • 29,788
  • 18
  • 89
  • 130
  • That's a good solution for how to make sure it's captured in all cases, so thanks for that. But I'm still interested to know why it throws on some machines but not on others ... – LordWilmore Nov 17 '16 at 10:56
  • 2
    This is hard to say with out more information – John Nov 17 '16 at 10:56