poorna2152 / nballerina

WebAssembly Backend for the nBallerina compiler
https://ballerina.io/
Apache License 2.0
4 stars 0 forks source link

Distinguish explicity thrown WASM errors in JS #19

Closed poorna2152 closed 2 years ago

poorna2152 commented 2 years ago

Explicitly thrown errors uses a tag to distinguish them. For example for,

But the error message emitted in the JS does not contain this tag thus it cannot distinguish between explicitly thrown errors https://github.com/WebAssembly/exception-handling/blob/main/proposals/exception-handling/Exceptions.md

poorna2152 commented 2 years ago

It is possible to do this by,

  1. Exporting the tags from the WASM module
  2. If an exception is thrown and check if it is of type WebAssembly.Exception.
  3. If so pass the exported tags one by one to the err.is(tag) function in WebAssembly.Exception class. Function returns true when a matching tag is found