@@ -36,8 +36,8 @@ succeeding instructions to process the data.
36
36
A WebAssembly exception is created when you throw it with the ` throw `
37
37
instruction. Thrown exceptions are handled as follows:
38
38
39
- 1 . They can be caught by one of ` catch ` /` catch_all ` / ` unwind ` blocks in an
40
- enclosing try block of a function body.
39
+ 1 . They can be caught by one of ` catch ` /` catch_all ` blocks in an enclosing try
40
+ block of a function body.
41
41
42
42
1 . Throws not caught within a function body continue up the call stack, popping
43
43
call frames, until an enclosing try block is found.
@@ -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
63
- unwind 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 block
63
+ 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
@@ -151,32 +151,6 @@ exception is thrown, or the exception is successfully caught by the catch block.
151
151
Because ` try ` and ` end ` instructions define a control-flow block, they can be
152
152
targets for branches (` br ` and ` br_if ` ) as well.
153
153
154
- ### Try-unwind blocks
155
-
156
- Try blocks can also be used with the ` unwind ` instruction. A try-unwind block
157
- contains an ` unwind ` block with the following form:
158
-
159
- ```
160
- try blocktype
161
- instruction*
162
- unwind
163
- instruction*
164
- end
165
- ```
166
-
167
- The ` unwind ` block is meant to contain cleanup instructions, such as
168
- destructors, in case any instruction in the corresponding try block throws. In
169
- case an exception is caught by the ` unwind ` block, it becomes the catching
170
- block.
171
-
172
- The ` end ` instruction at the end of ` unwind ` block is special that it
173
- automatically rethrows the current exception.
174
-
175
- When the program runs ` br ` within ` unwind ` block, the rest of the ` unwind ` block
176
- will not run and the program control will branch to the destination, as in
177
- normal blocks. Because we don't reach ` end ` of ` unwind ` block, rethrowing does
178
- not happen.
179
-
180
154
### Throwing an exception
181
155
182
156
The ` throw ` instruction takes an exception index as an immediate argument. That
@@ -202,8 +176,8 @@ flushed, the embedder defines how to handle uncaught exceptions. Otherwise, the
202
176
found enclosing try block is the catching try block.
203
177
204
178
A throw inside the body of a catch block is never caught by the corresponding
205
- try block of the catch/unwind block, since instructions in the body of the
206
- catch/unwind block are not in the body of the try block.
179
+ try block of the catch block, since instructions in the body of the catch block
180
+ are not in the body of the try block.
207
181
208
182
Once a catching try block is found for the thrown exception, the operand stack
209
183
is popped back to the size the operand stack had when the try block was entered
@@ -224,23 +198,15 @@ a `catch_all` block, the exception is rethrown.
224
198
If control is transferred to the body of a catch block, and the last instruction
225
199
in the body is executed, control then exits the try block.
226
200
227
- In case of a try-unwind block, if an exception is thrown within the try block,
228
- the program control is transfered to the body of ` unwind ` block. After executing
229
- instructions within the ` unwind ` block, the exception is automatically rethrown
230
- when the control reaches the ` end ` instruction. As in the case of the
231
- ` catch_all ` block, the exception arguments are not copied onto the operand
232
- stack.
233
-
234
- If the selected catch/unwind block does not throw an exception, it must yield
235
- the value(s) expected by the corresponding catching try block.
201
+ If the selected catch block does not throw an exception, it must yield the
202
+ value(s) expected by the corresponding catching try block.
236
203
237
204
Note that a caught exception can be rethrown using the ` rethrow ` instruction.
238
205
239
206
### Rethrowing an exception
240
207
241
- The ` rethrow ` instruction can only appear in the body of a
242
- catch/catch_all/unwind block. It always re-throws the exception caught by an
243
- enclosing catch block.
208
+ The ` rethrow ` instruction can only appear in the body of a catch/catch_all
209
+ block. It always re-throws the exception caught by an enclosing catch block.
244
210
245
211
Associated with the ` rethrow ` instruction is a _ label_ . The label is used to
246
212
disambiguate which exception is to be rethrown, when inside nested catch blocks.
297
263
The ` rethrow ` here references ` try $l2 ` , but the ` rethrow ` is not within its
298
264
` catch ` block.
299
265
300
- Also, the ` rethrow ` instruction cannot rethrow an exception caught
301
- by an unwind block. For example:
302
- ```
303
- try $l1
304
- unwind
305
- try $l2
306
- catch
307
- try $l3
308
- unwind
309
- rethrow label ;; only $l2 is valid
310
- end
311
- end
312
- end
313
- ```
314
-
315
266
### Try-delegate blocks
316
267
317
268
Try blocks can also be used with the ` delegate ` instruction. A try-delegate
@@ -326,8 +277,8 @@ delegate label
326
277
The ` delegate ` clause does not have an associated body, so try-delegate blocks
327
278
don't have an ` end ` instruction at the end. The ` delegate ` instruction takes a
328
279
label defined by a construct in which they are enclosed, and delegates exception
329
- handling to a catch/unwind block specified by the label. For example, consider
330
- this code:
280
+ handling to a catch block specified by the label. For example, consider this
281
+ code:
331
282
332
283
```
333
284
try $l1
@@ -373,10 +324,10 @@ uncaught exceptions. However, the details of this are left to the embedder.
373
324
374
325
#### Traps
375
326
376
- The ` catch ` /` catch_all ` / ` unwind ` instruction catches exceptions generated by the
377
- ` throw ` instruction, but does not catch traps. The rationale for this is that in
378
- general traps are not locally recoverable and are not needed to be handled in
379
- local scopes like try-catch.
327
+ The ` catch ` /` catch_all ` instruction catches exceptions generated by the ` throw `
328
+ instruction, but does not catch traps. The rationale for this is that in general
329
+ traps are not locally recoverable and are not needed to be handled in local
330
+ scopes like try-catch.
380
331
381
332
The ` catch ` instruction catches foreign exceptions generated from calls to
382
333
function imports as well, including JavaScript exceptions, with a few
@@ -406,7 +357,6 @@ The following rules are added to *instructions*:
406
357
407
358
```
408
359
try blocktype instruction* (catch instruction*)* (catch_all instruction*)? end |
409
- try blocktype instruction* unwind instruction* end |
410
360
try blocktype instruction* delegate label |
411
361
throw (exception except_index) |
412
362
rethrow label |
@@ -564,7 +514,6 @@ throws, and rethrows as follows:
564
514
| ` try ` | ` 0x06 ` | sig : ` blocktype ` | begins a block which can handle thrown exceptions |
565
515
| ` catch ` | ` 0x07 ` | index : ` varint32 ` | begins the catch block of the try block |
566
516
| ` catch_all ` | ` 0x19 ` | | begins the catch_all block of the try block |
567
- | ` unwind ` | ` 0x0a ` | | begins the unwind block of the try block |
568
517
| ` delegate ` | ` 0x18 ` | relative_depth : ` varuint32 ` | begins the delegate block of the try block |
569
518
| ` throw ` | ` 0x08 ` | index : ` varint32 ` | Creates an exception defined by the exception ` index ` and then throws it |
570
519
| ` rethrow ` | ` 0x09 ` | relative_depth : ` varuint32 ` | Pops the ` exnref ` on top of the stack and throws it |
0 commit comments