0

I have this code in a form

The form is empty.

There is no button, so no button named b1.

This code crashes, but the strange thing is it gives no exception.

I know it crashes, because it doesn't reach that MessageBox.Show line.

private void Form1_Load(object sender, EventArgs e)  {

  Control[] controlsreturned = this.Controls.Find("b1", false);
  MessageBox.Show(controlsreturned.Length.ToString()); //0
  controlsreturned[0].ToString();  // intentional crash to demonstrate issue
  MessageBox.Show("reached here?"); // is not reached! but no exception thrown!

}

As a test, one could try adding Button b1 = new Button(); b1.Name = "b1"; this.Controls.Add(b1); and then it won't crash.

But my point is, why is it that when it crashes it doesn't throw an exception, it just crashes very silently. The program continues to run.. no exception is thrown. This is of course a slightly bigger inconvenience in a larger program as it makes it a bit more work to debug. But I use a small example to demonstrate.

Nikhil Vartak
  • 5,002
  • 3
  • 26
  • 32
barlop
  • 12,887
  • 8
  • 80
  • 109
  • 1
    This 'could' be related to [C# silently fails](http://stackoverflow.com/questions/1583351/silent-failures-in-c-seemingly-unhandled-exceptions-that-does-not-crash-the-pr?rq=1) but I don't know if this is an x64 issues. – Stephen Ross May 23 '16 at 10:19
  • @StephenRoss yeah you're right. Interestingly I just tried wrapping it with a try catch and it caught /detected the exception – barlop May 23 '16 at 10:24
  • I cannot reproduce it. It's not silent at all but [breaking very load](http://fs5.directupload.net/images/160523/ib9modaf.jpg). – Tim Schmelter May 23 '16 at 10:27
  • @TimSchmelter If this is the x64 issue you'll have to make sure you're building in x64 for this to occur as it seems to be a Kernal issue. – Stephen Ross May 23 '16 at 10:28
  • @StephenRoss: still the same exception (shown in m link above) – Tim Schmelter May 23 '16 at 10:31

0 Answers0