W3cubDocs

/JavaScript

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.

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 the payload.

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).

Exceptions

TypeError

The payload and tag 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

Browser compatibility

Desktop Mobile Server
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet Deno Node.js
Exception
95
95
100
No
81
15.2
95
95
100
67
15.2
17.0
No
17.0.0
options_parameter_traceStack
95
95
100
No
81
15.2
95
95
100
67
15.2
17.0
No
17.0.0

See also

© 2005–2022 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception/Exception