The WebAssembly.Exception
object represents a runtime exception thrown from WebAssembly to JavaScript, or thrown from JavaScript to a WebAssembly exception handler.
The constructor accepts a WebAssembly.Tag
, an array of values, and an options
object as arguments. The tag uniquely defines the type of an exception, including the order of its arguments and their data types. The same tag that was used to create the Exception
is required to access the arguments of a thrown exception. Methods are provided to test whether an exception matches a particular tag, and also to get a particular value by index (if the exception matches specified tag).
JavaScript and other client code can only access WebAssembly exception values, and visa versa, when the associated tag is shared (you can't just use another tag that happens to define the same data types). Without the matching tag, exceptions can be caught and re-thrown, but they can't be inspected.
In order to make exception-throwing faster, exceptions thrown from WebAssembly generally do not include a stack trace. WebAssembly code that needs to provide a stack trace must call a JavaScript function to create the exception, passing options.traceStack=true
parameter in the constructor. The constructor may then return an exception with a stack trace attached to the stack
property.
Note: This feature is available in Web Workers