(tag...)
Import a tag function prototype that can be used to throw an exception that JavaScript can catch. This is used to declare what parameters and their data types will be sent when the exception is thrown.

Syntax

(import... (tag $label (param...)) )

Parameters

$label
The name of the tag function. This is used with the throw instruction.
(param...) Optional
Lists all the parameters the tag function will send when it is thrown.

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');
  }
}