I have null in one of the arguments in String.Format() , so NullReferenceException throws a NullReferenceException . Why is the check being performed, even the argument is not in the resulting string?
class Foo { public Exception Ex { get; set; } } class Program { public static void Main(string[] args) { var f1 = new Foo() { Ex = new Exception("Whatever") }; var f2 = new Foo(); var error1 = String.Format((f1.Ex == null) ? "Eror" : "Error: {0}", f1.Ex.Message);
Are there any workarounds other than two calls separated by if() ?
source share