プログラミング言語C#の throw 文に関するちょっとしたメモ。下記コードはコンパイルエラーとはならず、実際にはSystem.NullReferenceExceptionオブジェクトが送出される。
throw null; // throw new System.NullReferenceException();と等価
Standard ECMA-334 C# Language Specification(4th Ed.), 15.9.5 The throw statementより該当箇所を引用(下線部は強調)。
The
throwstatement throws an exception.throw-statement:
throwexpressionopt;A
throwstatement with an expression throws the value produced by evaluating the expression. The expression shall denote a value of the class typeSystem.Exceptionor of a class type that derives fromSystem.Exception. If evaluation of the expression producesnull, aSystem.NullReferenceExceptionis thrown instead.
(snip)
関連URL