WebAssembly.Exception constructor
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since May 2022.
The WebAssembly.Exception()
constructor is used to create a new WebAssembly.Exception
.
The constructor accepts a Tag
argument and a payload
array of data fields.
The data types of each of the payload elements must match the corresponding data type specified in the Tag
.
The constructor may also take an options
object.
The options.traceStack
property can be set true
(by default it is false
) to indicate that a Wasm stack trace may be attached to the exception's stack
property.
Syntax
new Exception(tag, payload)
new Exception(tag, payload, options)
Parameters
tag
-
An
WebAssembly.Tag
defining the data types expected for each of the values in thepayload
. payload
-
An array of one or more data fields comprising the payload of the exception. The elements must match the data types of the corresponding elements in the
tag
. If the number of data fields in the payload and their types don't match, aTypeError
exception is thrown. options
Optional Non-standard-
An object with the following optional fields:
traceStack
Optional Non-standard-
true
if theException
may have a stack trace attached to itsstack
property, otherwisefalse
. This isfalse
by default (ifoptions
oroptions.traceStack
are not provided).
Exceptions
TypeError
-
The
payload
andtag
sequences do not have the same number of elements and/or the elements are not of matching types.
Examples
This example shows the creation of an exception using a simple tag.
// Create tag and use it to create an exception
const tag = new WebAssembly.Tag({ parameters: ["i32", "f32"] });
const exception = new WebAssembly.Exception(tag, [42, 42.3]);
The stack
example shows the creation of an exception that uses the options
parameter.
Specifications
Specification |
---|
WebAssembly JavaScript Interface: Exception Handling # dom-exception-exception |
Browser compatibility
BCD tables only load in the browser