 <p>Don't know if this technique transfers from C/C++ to C#, but I've done this with macros:</p> <pre> #define CHECK_NULL(x) { (x) != NULL || \ fprintf(stderr, "The value of %s in %s, line %d is null.\n", \ #x, __FILENAME__, __LINE__); } </pre>