Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rethrow semantics question #259

Open
yamt opened this issue Feb 17, 2023 · 7 comments
Open

rethrow semantics question #259

yamt opened this issue Feb 17, 2023 · 7 comments

Comments

@yamt
Copy link
Contributor

yamt commented Feb 17, 2023

i'm reading https://github.com/WebAssembly/exception-handling/blob/main/proposals/exception-handling/Exceptions.md#rethrowing-an-exception
how the following should work was not clear to me.

try
catch
  try
    try 
    catch
      rethrow 2
    end
  catch ;; can this catch the rethrown exception?
  end
  ;; or, does the above rethrow work as if it was "rethrow 0" here?
end
@ioannad
Copy link
Collaborator

ioannad commented Feb 17, 2023

i'm reading https://github.com/WebAssembly/exception-handling/blob/main/proposals/exception-handling/Exceptions.md#rethrowing-an-exception how the following should work was not clear to me.

try
catch x <---- the exception that this catch caught is rethrown below
  try
    try 
    catch
      rethrow 2
    end
  catch x ;; can this catch the rethrown exception? --> yes, if the tag indices match
  end
  ;; or, does the above rethrow work as if it was "rethrow 0" here? --> no
end

rethrow n throws from its position, basically this searches the caught exception a val* in the (n+1)th surrounding block, (here the 3rd) then pushes the caught exception's values val* onto the stack and throws the tag address a.

There is a detailed example of how this works in "formal-examples" document.

@aheejin
Copy link
Member

aheejin commented Feb 17, 2023

This example may help understanding: #146 (comment)

@yamt
Copy link
Contributor Author

yamt commented Feb 18, 2023

thank you.
so, in the following, N=1 and N=0 refer the same exception?

try
  throw $tag1
catch_all
  try
    try
      throw $tag2
    catch_all
      rethrow 2
    end
  catch_all
    rethrow N
  end
end

@aheejin
Copy link
Member

aheejin commented Feb 18, 2023

Added the example to the explainer too: #263

@aheejin
Copy link
Member

aheejin commented Feb 18, 2023

thank you. so, in the following, N=1 and N=0 refer the same exception?

No.

try
  throw $tag1
catch_all      ;; N == 1 will rethrow the exception caught by this
  try
    try
      throw $tag2
    catch_all
      rethrow 2
    end
  catch_all    ;; N == 0 will rethrow the exception caught by this
    rethrow N
  end
end

@yamt
Copy link
Contributor Author

yamt commented Feb 18, 2023

thank you. so, in the following, N=1 and N=0 refer the same exception?

No.

try
  throw $tag1
catch_all      ;; N == 1 will rethrow the exception caught by this
  try
    try
      throw $tag2
    catch_all
      rethrow 2
    end
  catch_all    ;; N == 0 will rethrow the exception caught by this
    rethrow N
  end
end

i don't understand.

if N==0,

  1. "rethrow 2" rethrows the exception caught by the first catch_all
  2. the exception is caught by the third catch_all
  3. "rethrow N" rethrows the exception, which is the same exception "rethrow 2" rethrown.

if N==1,

  1. same
  2. same
  3. "rethrow N" rethrows the exception caught by the first catch_all

so, in both cases, the exception thrown by "rethrow N" is the exception caught by the first catch_all.

what am i missing?

@aheejin
Copy link
Member

aheejin commented Feb 18, 2023

Oh, you are talking about the program as a whole... Yeah, the whole program ends up throwing the same exception for N == 0 and N == 1. What I was describing was independent instruction's behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants