(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 "import" "integerException" (tag $integerException (param i32)))
(func (export "throwIntegerException")
i32.const 101
throw $integerException
)
try {
wasm.instance.exports.throwIntegerException();
} catch (e) {
if (e instanceof WebAssembly.Exception) {
if (e.is(tagIntegerException) === true) {
const value = e.getArg(tagIntegerException, 0);
console.log('IntegerException thrown value = ' + value);
} else {
console.log('Unknown WebAssembly.Exception');
}
} else {
console.log('Unknown exception');
}
}