1

I am curious about a very interesting thing, can give my query by a senario. Supposed I have written this code in my test method

[TestMethod]
Public void test method()
{
    String userId = null;
    Int lenght = userId.length;
}

In visual studio 2017 (as I am using this only)

It will throw nullreference exception through a pop-up which will say "userId was null".

As I have not handled through try and catch purposely.

Now I am curious about it that where did it get the parameter name ("userId") which was null... And if anyone knows about it please let me know if I can get the parameter name which was null in my catch block As in catch(Exception ex){ex.how_can_i_get_null_parameter}

. True help will be much appreciated may be a perfect answer can get a treat from me... For more details I will also attach screen shot of the pop-up as soon as I reach my work place.

  • 3
    Possible duplicate of [Getting the variable name for NullReferenceException](https://stackoverflow.com/questions/34442419/getting-the-variable-name-for-nullreferenceexception) – npo Dec 12 '18 at 19:08
  • 1
    This is almost certainly a debugger feature not a runtime feature since even debug builds don't include local variable names. – Mike Zboray Dec 12 '18 at 19:44
  • Where are the parameters in the above code segment? The method has none. – NoChance Dec 12 '18 at 19:53
  • Actually it was just a demo... No parameters are required... I have just reproduced... Nullreference exception... – shubham tunkikar Dec 15 '18 at 09:02

0 Answers0