Unnecessary checking??

  • Thread starter Thread starter Kevin Yu
  • Start date Start date
K

Kevin Yu

hi all

I have a question on the code I am reading.(#$Q%@ code).
anyway, there are checking on simple class instantiation, it checks for the
null return, but it just call the simple class constructor like this:

public someClass(){}

nothing is done in the constructor, but still checking for null return, *IF*
in the case of out of memory, will the runtime return null?? I know some C++
programmers do that check all the time. but is it necessary in .NET??


Kevin
 
Hi Kevin,

You are correct, from the documentations:

"If the new operator fails to allocate memory, it throws the exception
OutOfMemoryException."

so checking for null is a relic from the past :)
 
Back
Top