C # doesn't throw NullReferenceException on developer machine

I have some code that looks like this:

public partical class frmXXX : Form
{

  SomeObject foo = null;

  public void XYZ()
  {
    foo.ABC.DEF(foo.XXX, foo.YYY, foo.ZZZ);
    somethingElse();
  }

  ...

}

      

Looks like I had an error where I was calling XYZ()

when foo

it is null. The program crashed with a NullReferenceException on the client, which is what I would expect. However, on my development machine, I am not getting the exception. I also checked with the debugger that foo is actually null. The debugger says it is zero.

After calling the null object, the method will complete, so somethingElse();

it is not called. It looks like a silent exception. Is there a chance that my development machine is misconfigured or can I enable something?

+3


source to share


3 answers


Cntrl + Alt + E (or Debug -> Exceptions or in VS2017 Debug -> Windows -> Exception Settings ) Select Reset All , this will return default exceptions.



Also make sure Only My Code is checked . You can find this under Debug -> Options . This will take you to the Debugger -> General options . You can check My Code Only here .

+2


source


have you tried installing TryCatch:



public void XYZ()
  {

///try here
{
        foo.ABC.DEF(foo.XXX, foo.YYY, foo.ZZZ);
}
  ///catch
{
   return error here................
}
    somethingElse();
  }

      

0


source


You may have exclusion settings that are not standard. here is a useful link to both revert to default and tweak the settings to suit your needs.

you can check your settings with Ctrl + Alt + E as of 2015 - 2017

0


source







All Articles