WebAssembly.Exception constructor

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.


new Exception(tag, payload)
new Exception(tag, payload, options)



An WebAssembly.Tag defining the data types expected for each of the values in the 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, a TypeError exception is thrown.

options Optional Non-standard

An object with the following optional fields:

traceStack Optional Non-standard

true if the Exception may have a stack trace attached to its stack property, otherwise false. This is false by default (if options or options.traceStack are not provided).



The payload and tag sequences do not have the same number of elements and/or the elements are not of matching types.


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.


WebAssembly JavaScript Interface: Exception Handling
# dom-exception-exception

Browser compatibility

BCD tables only load in the browser

See also