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
* Update expressions.md
* build fixes
* Minor changes to bring this in line with the spec style and organization.
* Expression bodied member can be a throw expression.
* Add throw expression as a category into which an expression may be classified.
* Fix section number.
* fix merge error.
* add column end marker
* still rendering
* add one more escape
it appears that once any vertical bar is escaped in a table, they all must be.
* Add throw expressions to precedence table
* Move throw expression to a new top-level section after null coalescing operator
* Fix typo
* Update reference
* Update link to new section
Co-authored-by: Bill Wagner <[email protected]>
Co-authored-by: Bill Wagner <[email protected]>
Co-authored-by: Neal Gafter <[email protected]>
Co-authored-by: Jon Skeet <[email protected]>
Copy file name to clipboardExpand all lines: standard/expressions.md
+37-17Lines changed: 37 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,6 +24,7 @@ For expressions which occur as subexpressions of larger expressions, with the no
24
24
- A type. An expression with this classification can only appear as the left-hand side of a *member_access* ([§11.7.6](expressions.md#1176-member-access)). In any other context, an expression classified as a type causes a compile-time error.
25
25
- A method group, which is a set of overloaded methods resulting from a member lookup ([§11.5](expressions.md#115-member-lookup)). A method group may have an associated instance expression and an associated type argument list. When an instance method is invoked, the result of evaluating the instance expression becomes the instance represented by `this` ([§11.7.12](expressions.md#11712-this-access)). A method group is permitted in an *invocation_expression* ([§11.7.8](expressions.md#1178-invocation-expressions)) or a *delegate_creation_expression* ([§11.7.15.6](expressions.md#117156-delegate-creation-expressions)), and can be implicitly converted to a compatible delegate type ([§10.8](conversions.md#108-method-group-conversions)). In any other context, an expression classified as a method group causes a compile-time error.
26
26
- An event access. Every event access has an associated type, namely the type of the event. Furthermore, an event access may have an associated instance expression. An event access may appear as the left-hand operand of the `+=` and `-=` operators ([§11.18.4](expressions.md#11184-event-assignment)). In any other context, an expression classified as an event access causes a compile-time error. When an accessor of an instance event access is invoked, the result of evaluating the instance expression becomes the instance represented by `this` ([§11.7.12](expressions.md#11712-this-access)).
27
+
- A throw expression, which may be used is several contexts to throw an exception in an expression. A throw expression may be converted by an implicit conversion to any type.
27
28
28
29
A property access or indexer access is always reclassified as a value by performing an invocation of the *get_accessor* or the *set_accessor*. The particular accessor is determined by the context of the property or indexer access: If the access is the target of an assignment, the *set_accessor* is invoked to assign a new value ([§11.18.2](expressions.md#11182-simple-assignment)). Otherwise, the *get_accessor* is invoked to obtain the current value ([§11.2.2](expressions.md#1122-values-of-expressions)).
29
30
@@ -139,23 +140,23 @@ The precedence of an operator is established by the definition of its associated
@@ -4238,6 +4240,24 @@ The type of the expression `a ?? b` depends on which implicit conversions are
4238
4240
4239
4241
Otherwise, `a` and `b` are incompatible, and `a` compile-time error occurs.
4240
4242
4243
+
## §throw-expression-operator-new-clause The throw expression operator
4244
+
4245
+
```ANTLR
4246
+
throw_expression
4247
+
: 'throw' null_coalescing_expression
4248
+
;
4249
+
```
4250
+
4251
+
A *throw_expression* throws the value produced by evaluating the *null_coalescing_expression*. The expression shall be implicitly convertible to `System.Exception`, and the result of evaluating the expression is converted to `System.Exception` before being thrown. 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)).
4252
+
4253
+
A *throw_expression* has no type. A *throw_expression* is convertible to every type by an *implicit throw conversion*.
4254
+
4255
+
A *throw expression* shall only occur in the following syntactic contexts:
4256
+
4257
+
- As the second or third operand of a ternary conditional operator (`?:`).
4258
+
- As the second operand of a null coalescing operator (`??`).
4259
+
- As the body of an expression-bodied lambda or member.
4260
+
4241
4261
## 11.15 Conditional operator
4242
4262
4243
4263
The `?:` operator is called the conditional operator. It is at times also called the ternary operator.
0 commit comments