Jason Bock

Home Biography Speaking Articles Books Music

Constructors Returning Null (?)

A couple of days ago I saw some code that left me speechless:

FileInfo file = new FileInfo("somefilepath");

if(file == null)
{
  // ...
}

Look at the code in bold. If a constructor fails, you get an exception - I’ve never seen the new operator return null.

Is this just wrong as wrong can be, or am I missing something?

Published: 09.19.2007 11:48:34 AM CST