Skip to content

Commit a0e273c

Browse files
committed
Clarify delegate targetting function-level block
This clarifies that `delegate` can target the function-level block, which means the exception is thrown to the caller. Also added a few more examples. Fixes WebAssembly#176.
1 parent 9fda8b6 commit a0e273c

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

proposals/exception-handling/Exceptions.md

+32-2
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,7 @@ end
288288
If `call $foo` throws, searching for a catching block first finds `delegate`,
289289
and because it delegates exception handling to catching instructions associated
290290
with `$l1`, it will be next checked by the outer `catch` and then `catch_all`
291-
instructions. When the specified label within a `delegate` instruction does not
292-
correspond to a `try` instruction, it is a validation failure.
291+
instructions.
293292

294293
Note that the example below is a validation failure:
295294
```
@@ -311,6 +310,37 @@ catching instructions (`catch`/`catch_all`/`delegate`) come after the
311310
same as if the `try` has catches but none of the catches are able to handle the
312311
exception.
313312

313+
If `delegate`'s immediate argument is the depth of block-like structures
314+
(blocks, loops, and trys) + 1, i.e., the function-level block, it is considered
315+
to be delegating the exception to the caller of the current function. For
316+
example:
317+
```
318+
try $l1
319+
try
320+
call $foo
321+
delegate 1 ;; delegate to the caller
322+
catch
323+
...
324+
catch_all
325+
...
326+
end
327+
```
328+
In case `foo` throws, `delegate 1` here delegates the exception handling to the
329+
caller, i.e., the exception escapes the current function.
330+
331+
When the specified label within a `delegate` instruction does not correspond to
332+
a `try` instruction or the function-level, it is a validation failure:
333+
```
334+
block $l0
335+
loop $l1
336+
try
337+
call $foo
338+
delegate $l0 ;; targets a 'block', validation failure
339+
delegate $l1 ;; targets a 'loop', validation failure
340+
end
341+
end
342+
```
343+
314344
### JS API
315345

316346
#### Stack traces

0 commit comments

Comments
 (0)