exception-handling
exception-handling copied to clipboard
rethrow semantics question
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
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.
This example may help understanding: https://github.com/WebAssembly/exception-handling/issues/146#issuecomment-777714491
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
Added the example to the explainer too: #263
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
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,
- "rethrow 2" rethrows the exception caught by the first catch_all
- the exception is caught by the third catch_all
- "rethrow N" rethrows the exception, which is the same exception "rethrow 2" rethrown.
if N==1,
- same
- same
- "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?
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.