Ambiguity/identity loss when (re)throwing external exceptions #207
Description
To handle an external exception, for example originating in JavaScript, one would naturally use a catch_all
clause iiuc. The caught exception can (only) be rethrow
n unmodified as long as it does not escape the scope of the catch clause, implying some limitations. To give an example of what I mean, imagine the following pseudocode in Wasm with EH:
try {
maybeThrowExternalException();
} catch (Exception ex) {
// ...
}
where ex
cannot refer to the original exception since there is no such reference available when using a catch_all
clause, so a compiler will likely utilize a substitute, say an ExternalException
instance to represent the exception. When raising the exception again, this leads to an ambiguity within the catch clause if a language does not itself have an expression-less throw;
instruction (JS for example considers this a syntax error) or likewise to indicate the intent to rethrow:
try {
maybeThrowExternalException();
} catch (Exception ex) {
throw ex; // rethrow the original or throw the substitute? what if ex is modified?
}
Furthermore, if the exception escapes the catch clause, the only available option becomes to throw the substitute, with the exception losing identity and being unable to refer to the original exception due the unavailable reference:
Exception escapedException;
try {
maybeThrowExternalException();
} catch (Exception ex) {
escapedException = ex;
}
if (escapedException) throw ex; // throw the substitute
Now I know that exnref
has been removed for reasons, yet being able to reference an (external) exception in catch_all
seems useful. Externally in JS this is not a problem because there is such a reference, a WebAssembly.Exception
. Could there perhaps be a similar reference in Wasm when using/limited to a catch_all
clause? Or are there clever tricks to emulate the desired behavior in a portable way?
Related: #202