@@ -59,8 +59,8 @@ may send values back to the suspended instruction, allowing the originating code
59
59
to resume.
60
60
61
61
Exceptions are a special case of an event in that they never resume. Similarly,
62
- a throw instruction is the suspending event of an exception. The catch or unwind
63
- block associated with a try block defines how to handle the throw.
62
+ a ` throw ` instruction is the suspending event of an exception. The catch or
63
+ unwind block associated with a try block defines how to handle the throw.
64
64
65
65
WebAssembly events (i.e. exceptions) are defined by a new ` event ` section of a
66
66
WebAssembly module. The event section is a list of declared events associated
@@ -93,8 +93,8 @@ Exception indices are used by:
93
93
1 . The ` throw ` instruction which creates a WebAssembly exception with the
94
94
corresponding exception tag, and then throws it.
95
95
96
- 2 . The ` catch ` instruction uses the tag to identify if the thrown exception is
97
- one it can catch. If true it pushes the corresponding argument values of the
96
+ 2 . The ` catch ` clause uses the tag to identify if the thrown exception is one it
97
+ can catch. If true it pushes the corresponding argument values of the
98
98
exception onto the stack.
99
99
100
100
### Try-catch blocks
161
161
```
162
162
163
163
The ` unwind ` block is meant to contain cleanup instructions, such as
164
- destructors, in case any instruction in the corresponding try block throws.
165
- In case an exception is caught by the ` unwind ` block, it becomes the catching
164
+ destructors, in case any instruction in the corresponding try block throws. In
165
+ case an exception is caught by the ` unwind ` block, it becomes the catching
166
166
block.
167
167
168
168
The ` end ` instruction at the end of ` unwind ` block is special that it
@@ -197,19 +197,20 @@ try block of the catch/unwind block, since instructions in the body of the
197
197
catch/unwind block are not in the body of the try block.
198
198
199
199
Once a catching try block is found for the thrown exception, the operand stack
200
- is popped back to the size the operand stack had when the try block was entered after possible block parameters were popped.
200
+ is popped back to the size the operand stack had when the try block was entered
201
+ after possible block parameters were popped.
201
202
202
- Then in case of a try-catch block, tagged catch blocks are tried in the
203
- order they appear in the catching try block, until one matches. If a matched
204
- tagged catch block is found, control is transferred to the body of the catch
205
- block, and the data fields of the exception are pushed back onto the stack.
203
+ Then in case of a try-catch block, tagged catch blocks are tried in the order
204
+ they appear in the catching try block, until one matches. If a matched tagged
205
+ catch block is found, control is transferred to the body of the catch block, and
206
+ the data fields of the exception are pushed back onto the stack.
206
207
207
208
Otherwise, control is transferred to the body of the ` catch_all ` block, if any.
208
209
However, unlike tagged catch blocks, the constructor arguments are not copied
209
210
back onto the operand stack.
210
211
211
- If no tagged catch blocks were matched, and the
212
- catching try block doesn't have a ` catch_all ` block, the exception is rethrown.
212
+ If no tagged catch blocks were matched, and the catching try block doesn't have
213
+ a ` catch_all ` block, the exception is rethrown.
213
214
214
215
If control is transferred to the body of a catch block, and the last instruction
215
216
in the body is executed, control then exits the try block.
@@ -263,12 +264,12 @@ end
263
264
```
264
265
265
266
In this example, ` N ` is used to disambiguate which caught exception is being
266
- rethrown. It could rethrow any of the three caught expceptions. Hence,
267
- ` rethrow 0` corresponds to the exception caught by ` catch 3 ` , ` rethrow 1 `
268
- corresponds to the exception caught by ` catch 2 ` , and ` rethrow 3 ` corresponds
269
- to the exception caught by ` catch 1 ` . In wat format, the argument for the
270
- ` rethrow ` instructions can also be written as a label, like branches. So
271
- ` rethrow 0 ` in the example above can also be written as ` rethrow $l3 ` .
267
+ rethrown. It could rethrow any of the three caught expceptions. Hence, `rethrow
268
+ 0` corresponds to the exception caught by ` catch 3` , ` rethrow 1` corresponds to
269
+ the exception caught by ` catch 2 ` , and ` rethrow 3 ` corresponds to the exception
270
+ caught by ` catch 1 ` . In wat format, the argument for the ` rethrow ` instructions
271
+ can also be written as a label, like branches. So ` rethrow 0 ` in the example
272
+ above can also be written as ` rethrow $l3 ` .
272
273
273
274
Note that ` rethrow 2 ` is not allowed because it does not reference a catch
274
275
block. Rather, it references a ` block ` instruction, so it will result in a
@@ -298,11 +299,11 @@ try blocktype
298
299
delegate label
299
300
```
300
301
301
- The ` delegate ` clause does not have an associated body, so try-delegate
302
- blocks don't have an ` end ` instruction at the end. The ` delegate ` instruction
303
- takes a label defined by a construct in which they are enclosed, and delegates
304
- exception handling to a catch/unwind block specified by the label. For example,
305
- consider this code:
302
+ The ` delegate ` clause does not have an associated body, so try-delegate blocks
303
+ don't have an ` end ` instruction at the end. The ` delegate ` instruction takes a
304
+ label defined by a construct in which they are enclosed, and delegates exception
305
+ handling to a catch/unwind block specified by the label. For example, consider
306
+ this code:
306
307
307
308
```
308
309
try $l1
318
319
319
320
If ` call $foo ` throws, searching for a catching block first finds ` delegate ` ,
320
321
and because it delegates exception handling to catching instructions associated
321
- with ` $l1 ` , it will be next checked by the outer ` catch ` and then
322
- ` catch_all ` instructions.
323
- When the specified label within a ` delegate `
324
- instruction does not correspond to a ` try ` instruction, it is a validation
325
- failure.
322
+ with ` $l1 ` , it will be next checked by the outer ` catch ` and then ` catch_all `
323
+ instructions. When the specified label within a ` delegate ` instruction does not
324
+ correspond to a ` try ` instruction, it is a validation failure.
326
325
327
326
Note that the example below is a validation failure:
328
327
```
0 commit comments