Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

Commit 6d71748

Browse files
authored
Clarify catchless try in explainer (#168)
- Removes the sentence that catchless `try` is the same as a regular `block`, because it can be targetted by `delegate`. - Improves a few sentences - Adds examples for catchless try
1 parent 844e813 commit 6d71748

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

proposals/exception-handling/Exceptions.md

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,7 @@ A try-catch block contains zero or more `catch` blocks and zero or one
115115
`catch_all` block. All `catch` blocks must precede the `catch_all` block, if
116116
any. The `catch`/`catch_all` instructions (within the try construct) are called
117117
the _catching_ instructions. There may not be any `catch` or `catch_all` blocks
118-
after a `try`, in which case the whole `try` block is effectively a regular
119-
block.
118+
after a `try`, in which case the `try` block does not catch any exceptions.
120119

121120
The _body_ of the try block is the list of instructions before the first
122121
catching instruction. The _body_ of each catch block is the sequence of
@@ -241,9 +240,9 @@ caught by `catch 1`. In wat format, the argument for the `rethrow` instructions
241240
can also be written as a label, like branches. So `rethrow 0` in the example
242241
above can also be written as `rethrow $l3`.
243242

244-
Note that `rethrow 2` is not allowed because it does not reference a catch
245-
block. Rather, it references a `block` instruction, so it will result in a
246-
validation failure.
243+
Note that `rethrow 2` is not allowed because it does not refer to a `try` label
244+
from within its catch block. Rather, it references a `block` instruction, so it
245+
will result in a validation failure.
247246

248247
Note that the example below is a validation failure:
249248
```
@@ -271,9 +270,8 @@ delegate label
271270

272271
The `delegate` clause does not have an associated body, so try-delegate blocks
273272
don't have an `end` instruction at the end. The `delegate` instruction takes a
274-
label defined by a construct in which they are enclosed, and delegates exception
275-
handling to a catch block specified by the label. For example, consider this
276-
code:
273+
try label and delegates exception handling to a `catch`/`catch_all`/`delegate`
274+
specified by the `try` label. For example, consider this code:
277275

278276
```
279277
try $l1
@@ -296,17 +294,22 @@ correspond to a `try` instruction, it is a validation failure.
296294
Note that the example below is a validation failure:
297295
```
298296
try $l1
299-
catch 1
297+
catch
300298
try
301299
call $foo
302300
delegate $l1 ;; (= delegate 0)
303301
catch_all
304302
...
305303
end
306304
```
307-
Here `delegate` is trying to delegate to `catch 1`, which exists before the
308-
`delegate`. The `delegate` instruction can only delegate to `catch`/`catch_all`
309-
blocks in a `try` or to another `delegate` below the `delegate` itself.
305+
Here `delegate` is trying to delegate to `catch`, which exists before the
306+
`delegate`. The `delegate` instruction can only target `try` label whose
307+
catching instructions (`catch`/`catch_all`/`delegate`) come after the
308+
`delegate` instruction.
309+
310+
`delegate` can also target `catch`-less `try`, in which case the effect is the
311+
same as if the `try` has catches but none of the catches are able to handle the
312+
exception.
310313

311314
### JS API
312315

0 commit comments

Comments
 (0)