WebAssembly.Tag
Create an exception function prototype tag that can be imported into a WASM module. This declares what the exception is and what parameters to except if it is thrown within the WASM module.

Constructor

const tag = new WebAssembly.Tag(options);

Parameters

options
Declares what the tag exception should look like.
options.parameters
An array of strings giving the list of parameter data types the exception will return when thrown. These can be one of the following. "i32", "i64", "f32" or "f64".

Example

;; Import exception (used with a single i32 value)
(import "import" "integerException" (tag $integerException (param i32)))

;; Create function that will throw the exception
(func (export "throwIntegerException")
  ;; Push the exception parameters on to the stack
  i32.const 101

  ;; Then throw the tag/exception
  throw $integerException
)
try {
  // Call the function that will throw the exception
  wasm.instance.exports.throwIntegerException();
} catch (e) {
  // Check it is a Web Assembly exception
  if (e instanceof WebAssembly.Exception) {
    // Check it is the right tag
    if (e.is(tagIntegerException) === true) {
      // Get the arguments
      const value = e.getArg(tagIntegerException, 0);

      // Log result
      console.log('IntegerException thrown value = ' + value);
    } else {
      // Log error
      console.log('Unknown WebAssembly.Exception');
    }
  } else {
    // Log error
    console.log('Unknown exception');
  }
}