288
288
If ` call $foo ` throws, searching for a catching block first finds ` delegate ` ,
289
289
and because it delegates exception handling to catching instructions associated
290
290
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.
293
292
294
293
Note that the example below is a validation failure:
295
294
```
@@ -311,6 +310,37 @@ catching instructions (`catch`/`catch_all`/`delegate`) come after the
311
310
same as if the ` try ` has catches but none of the catches are able to handle the
312
311
exception.
313
312
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
+
314
344
### JS API
315
345
316
346
#### Stack traces
0 commit comments