From 1609a1ffb42c1881caad11ecf17bc35f375ede8a Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Sat, 26 Jun 2021 23:49:13 -0700 Subject: [PATCH 1/5] Clarify catchless try in explainer - Removes the sentence that catchless `try` is the same as a regular `block`, because it can be targetted by `delegate`. - Improves a few sentences - Adds examples for catchless try Closes #164. --- proposals/exception-handling/Exceptions.md | 34 ++++++++++++++++------ 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/proposals/exception-handling/Exceptions.md b/proposals/exception-handling/Exceptions.md index d3881ca7..8723b062 100644 --- a/proposals/exception-handling/Exceptions.md +++ b/proposals/exception-handling/Exceptions.md @@ -115,8 +115,8 @@ A try-catch block contains zero or more `catch` blocks and zero or one `catch_all` block. All `catch` blocks must precede the `catch_all` block, if any. The `catch`/`catch_all` instructions (within the try construct) are called the _catching_ instructions. There may not be any `catch` or `catch_all` blocks -after a `try`, in which case the whole `try` block is effectively a regular -block. +after a `try`, in which case the `try` block does not catch any exceptions and +rethrows them. The _body_ of the try block is the list of instructions before the first catching instruction. The _body_ of each catch block is the sequence of @@ -258,6 +258,18 @@ end The `rethrow` here references `try $l2`, but the `rethrow` is not within its `catch` block. +Also, targetting a label of `catch`-less `try` or `try`-`delegate` is also a +validation failure, because `rethrow` is not within a `catch` or `catch_all`. +``` +try $l1 + rethrow $l1 ;; validation failure! +delegate + +try $l2 + rethrow $l2 ;; validation failure! +end +``` + ### Try-delegate blocks Try blocks can also be used with the `delegate` instruction. A try-delegate @@ -271,9 +283,8 @@ delegate label The `delegate` clause does not have an associated body, so try-delegate blocks don't have an `end` instruction at the end. The `delegate` instruction takes a -label defined by a construct in which they are enclosed, and delegates exception -handling to a catch block specified by the label. For example, consider this -code: +try label and delegates exception handling to a `catch`/`catch_all`/`delegate` +specified by the `try` label. For example, consider this code: ``` try $l1 @@ -296,7 +307,7 @@ correspond to a `try` instruction, it is a validation failure. Note that the example below is a validation failure: ``` try $l1 -catch 1 +catch try call $foo delegate $l1 ;; (= delegate 0) @@ -304,9 +315,14 @@ catch_all ... end ``` -Here `delegate` is trying to delegate to `catch 1`, which exists before the -`delegate`. The `delegate` instruction can only delegate to `catch`/`catch_all` -blocks in a `try` or to another `delegate` below the `delegate` itself. +Here `delegate` is trying to delegate to `catch`, which exists before the +`delegate`. The `delegate` instruction can only target `try` label whose +catching instructions (`catch`/`catch_all`/`delegate`) come after the +`delegate` instruction. + +`delegate` can also target `catch`-less `try`, in which case the effect is the +same as the `try` has catches but none of the catches are able to handle the +exception. ### JS API From 45942b9a1e6441e9d99d21910189537eb77b359c Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Tue, 29 Jun 2021 01:30:14 -0700 Subject: [PATCH 2/5] Update proposals/exception-handling/Exceptions.md Co-authored-by: Andreas Rossberg --- proposals/exception-handling/Exceptions.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/proposals/exception-handling/Exceptions.md b/proposals/exception-handling/Exceptions.md index 8723b062..6213f0ef 100644 --- a/proposals/exception-handling/Exceptions.md +++ b/proposals/exception-handling/Exceptions.md @@ -115,8 +115,7 @@ A try-catch block contains zero or more `catch` blocks and zero or one `catch_all` block. All `catch` blocks must precede the `catch_all` block, if any. The `catch`/`catch_all` instructions (within the try construct) are called the _catching_ instructions. There may not be any `catch` or `catch_all` blocks -after a `try`, in which case the `try` block does not catch any exceptions and -rethrows them. +after a `try`, in which case the `try` block does not catch any exceptions. The _body_ of the try block is the list of instructions before the first catching instruction. The _body_ of each catch block is the sequence of From d73ad32a9da188d03bb9e070aa677780d00670d6 Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Tue, 29 Jun 2021 01:37:48 -0700 Subject: [PATCH 3/5] Remove misleading paragraph about `rethrow` --- proposals/exception-handling/Exceptions.md | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/proposals/exception-handling/Exceptions.md b/proposals/exception-handling/Exceptions.md index 6213f0ef..46d0b1f2 100644 --- a/proposals/exception-handling/Exceptions.md +++ b/proposals/exception-handling/Exceptions.md @@ -240,9 +240,9 @@ caught by `catch 1`. In wat format, the argument for the `rethrow` instructions can also be written as a label, like branches. So `rethrow 0` in the example above can also be written as `rethrow $l3`. -Note that `rethrow 2` is not allowed because it does not reference a catch -block. Rather, it references a `block` instruction, so it will result in a -validation failure. +Note that `rethrow 2` is not allowed because it does not refer to a `try` label +with a catch block. Rather, it references a `block` instruction, so it will +result in a validation failure. Note that the example below is a validation failure: ``` @@ -257,18 +257,6 @@ end The `rethrow` here references `try $l2`, but the `rethrow` is not within its `catch` block. -Also, targetting a label of `catch`-less `try` or `try`-`delegate` is also a -validation failure, because `rethrow` is not within a `catch` or `catch_all`. -``` -try $l1 - rethrow $l1 ;; validation failure! -delegate - -try $l2 - rethrow $l2 ;; validation failure! -end -``` - ### Try-delegate blocks Try blocks can also be used with the `delegate` instruction. A try-delegate From 64a9296b73c2824d918b3b74d8bb7c2c72f1942b Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Tue, 29 Jun 2021 02:03:49 -0700 Subject: [PATCH 4/5] Apply suggestions from code review Co-authored-by: Andreas Rossberg --- proposals/exception-handling/Exceptions.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/proposals/exception-handling/Exceptions.md b/proposals/exception-handling/Exceptions.md index 46d0b1f2..e7dcaaeb 100644 --- a/proposals/exception-handling/Exceptions.md +++ b/proposals/exception-handling/Exceptions.md @@ -241,7 +241,7 @@ can also be written as a label, like branches. So `rethrow 0` in the example above can also be written as `rethrow $l3`. Note that `rethrow 2` is not allowed because it does not refer to a `try` label -with a catch block. Rather, it references a `block` instruction, so it will +from within its catch block. Rather, it references a `block` instruction, so it will result in a validation failure. Note that the example below is a validation failure: @@ -308,7 +308,7 @@ catching instructions (`catch`/`catch_all`/`delegate`) come after the `delegate` instruction. `delegate` can also target `catch`-less `try`, in which case the effect is the -same as the `try` has catches but none of the catches are able to handle the +same as if the `try` has catches but none of the catches are able to handle the exception. ### JS API From c3f4180c0801ab27b8d9ce57419428ad2870a53b Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Tue, 29 Jun 2021 02:04:25 -0700 Subject: [PATCH 5/5] 80 cols --- proposals/exception-handling/Exceptions.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/proposals/exception-handling/Exceptions.md b/proposals/exception-handling/Exceptions.md index e7dcaaeb..ee89a25b 100644 --- a/proposals/exception-handling/Exceptions.md +++ b/proposals/exception-handling/Exceptions.md @@ -241,8 +241,8 @@ can also be written as a label, like branches. So `rethrow 0` in the example above can also be written as `rethrow $l3`. Note that `rethrow 2` is not allowed because it does not refer to a `try` label -from within its catch block. Rather, it references a `block` instruction, so it will -result in a validation failure. +from within its catch block. Rather, it references a `block` instruction, so it +will result in a validation failure. Note that the example below is a validation failure: ```