.net - Would simple class instantiation ever fail in C#? -


I saw some code written by another developer who looks something like this:

  var Stringbuilder = new stringbilder (); If (stringbuilder == zero) {// log memory allocation error // ... return; }  

(this code is everywhere)

Question 1: Will this error logging code also be called? If there is no memory, then System.OutOfMemoryException will be thrown on the first code?

Question 2: Can the call to a producer ever be empty?

You are right, and that code is wrong. It will throw outmounter exposure on failure:

"If the new operator fails to allocate memory, then the exception throws an out-of-memory exception."

Constructors do not return anything, tap alone, they manipulate the object that has already been allocated.


Comments