throw
Throws an exception for JavaScript to catch. This can only throw imported (tag...)
objects. These are used
to declare the parameters that will be sent with the exception.
Syntax
throw $tagFunction
Parameters
$tagFunction
The name of the tag function that will be thrown.
Stack In
* |
Any of the parameters the exception tag function requires. |
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');
}
}