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