proposals/csharp-7.0/throw-expression.md
Champion issue: https://github.com/dotnet/csharplang/issues/62
We extend the set of expression forms to include
throw_expression
: 'throw' null_coalescing_expression
;
null_coalescing_expression
: throw_expression
;
The type rules are as follows:
A throw expression throws the value produced by evaluating the null_coalescing_expression, which must denote a value of the class type System.Exception, of a class type that derives from System.Exception or of a type parameter type that has System.Exception (or a subclass thereof) as its effective base class. If evaluation of the expression produces null, a System.NullReferenceException is thrown instead.
The behavior at runtime of the evaluation of a throw expression is the same as specified for a throw statement (§12.10.6).
The flow-analysis rules are as follows:
A throw expression is permitted in only the following syntactic contexts:
?:??