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

Clarify delegate targetting function-level block #177

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions proposals/exception-handling/Exceptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,7 @@ end
If `call $foo` throws, searching for a catching block first finds `delegate`,
and because it delegates exception handling to catching instructions associated
with `$l1`, it will be next checked by the outer `catch` and then `catch_all`
instructions. When the specified label within a `delegate` instruction does not
correspond to a `try` instruction, it is a validation failure.
instructions.

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

If `delegate`'s immediate argument is the depth of block-like structures
(blocks, loops, and trys) + 1, i.e., the function-level block, it is considered
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand what you mean by: "the depth of block-like structures (...) + 1" and how this is related to the function-level block case. Or did you mean that in this case the depth is not a block-like structure?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand what you meant now. What do you think about this phrasing: "the depth of the outermost block + 1, i.e. the function-level block (...)"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Also added that it will be considered as a catchless try.

to be delegating the exception to the caller of the current function. For
example:
```
try $l1
try
call $foo
delegate 1 ;; delegate to the caller
catch
...
catch_all
...
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make the example complete I think it should be wrapped in a function, otherwise it is ambiguous what the outer scope is.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

```
In case `foo` throws, `delegate 1` here delegates the exception handling to the
caller, i.e., the exception escapes the current function.

When the specified label within a `delegate` instruction does not correspond to
a `try` instruction or the function-level, it is a validation failure:
```
block $l0
loop $l1
try
call $foo
delegate $l0 ;; targets a 'block', validation failure
try
call $foo
delegate $l1 ;; targets a 'loop', validation failure
end
end
```

### JS API

#### Stack traces
Expand Down