You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: standard/expressions.md
+28-30Lines changed: 28 additions & 30 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2844,36 +2844,6 @@ named_entity_target
2844
2844
;
2845
2845
```
2846
2846
2847
-
### §throw-expression-operator-new-clause The throw expression operator
2848
-
2849
-
```antlr
2850
-
throw_expression
2851
-
: 'throw' null_coalescing_expression
2852
-
;
2853
-
```
2854
-
2855
-
A *throw_expression* throws the value produced by evaluating the *null_coalescing_expression*, which shall denote a value of the class type `System.Exception`, a value of a class type that derives from `System.Exception` or a value 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` shall be thrown instead.
2856
-
2857
-
The behavior at runtime of the evaluation of a *throw expression* is the same as specified for a *throw statement* ([§13.10.6](expressions.md#13106-the-throw-statement)).
2858
-
2859
-
The type rules are as follows:
2860
-
2861
-
- A *throw_expression* has no type.
2862
-
- A *throw_expression* is convertible to every type by an implicit conversion.
2863
-
2864
-
The flow-analysis rules are as follows:
2865
-
2866
-
- For every variable *v*, *v* is definitely assigned before the *null_coalescing_expression* of a *throw_expression* iff it is definitely assigned before the *throw_expression*.
2867
-
- For every variable *v*, *v* is definitely assigned after *throw_expression*.
2868
-
2869
-
A *throw expression* shall only occur in the following syntactic contexts:
2870
-
2871
-
- As the second or third operand of a ternary conditional operator (`?:`), but not both.
2872
-
- As the second operand of a null coalescing operator (`??`).
2873
-
- As the body of an expression-bodied lambda or method.
2874
-
2875
-
## 12.8 Unary operators
2876
-
2877
2847
Because `nameof` is not a keyword, a *nameof_expression* is always syntactically ambiguous with an invocation of the simple name `nameof`. For compatibility reasons, if a name lookup ([§11.7.4](expressions.md#1174-simple-names)) of the name `nameof` succeeds, the expression is treated as an *invocation_expression* — regardless of whether the invocation is valid. Otherwise it is a *nameof_expression*.
2878
2848
2879
2849
Simple name and member access lookups are performed on the *named_entity* at compile time, following the rules described in [§11.7.4](expressions.md#1174-simple-names) and [§11.7.6](expressions.md#1176-member-access). However, where the lookup described in [§11.7.4](expressions.md#1174-simple-names) and [§11.7.6](expressions.md#1176-member-access) results in an error because an instance member was found in a static context, a *nameof_expression* produces no such error.
@@ -2942,6 +2912,34 @@ These are the same transformations applied in [§6.4.3](lexical-structure.md#643
### §throw-expression-operator-new-clause The throw expression operator
2916
+
2917
+
```ANTLR
2918
+
throw_expression
2919
+
:'throw'null_coalescing_expression
2920
+
;
2921
+
```
2922
+
2923
+
A *throw_expression* throws the value produced by evaluating the *null_coalescing_expression*, which shall denote a value of the class type `System.Exception`, a value of a class type that derives from `System.Exception` or a value 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` shall be thrown instead.
2924
+
2925
+
The behavior at runtime of the evaluation of a *throw expression* is the same as specified for a *throw statement* ([§12.10.6](statements.md#12106-the-throw-statement)).
2926
+
2927
+
The type rules are as follows:
2928
+
2929
+
- A *throw_expression* has no type.
2930
+
- A *throw_expression* is convertible to every type by an implicit conversion.
2931
+
2932
+
The flow-analysis rules are as follows:
2933
+
2934
+
- For every variable *v*, *v* is definitely assigned before the *null_coalescing_expression* of a *throw_expression* iff it is definitely assigned before the *throw_expression*.
2935
+
- For every variable *v*, *v* is definitely assigned after *throw_expression*.
2936
+
2937
+
A *throw expression* shall only occur in the following syntactic contexts:
2938
+
2939
+
- As the second or third operand of a ternary conditional operator (`?:`), but not both.
2940
+
- As the second operand of a null coalescing operator (`??`).
2941
+
- As the body of an expression-bodied lambda or method.
0 commit comments