Get to know MDN better
This feature is well established and works across many devices and browser versions. It’s been available across browsers since May 2022.
* Some parts of this feature may have varying levels of support.
The WebAssembly.Tag object represents a WebAssembly exception type that can be thrown in a Wasm module.
Creates a new WebAssembly.Tag object instance.
Returns the object defining the data-types array for the tag (as set in its constructor).
WebAssembly modules can define exception types using the tag module definition. Exceptions of those types can then be thrown using the throw instruction, and caught and handled using try_table blocks containing catch clauses.
If wished, you can define a Wasm exception type in the JavaScript host using the WebAssembly.Tag() constructor, before importing it into the Wasm module to use there.
One of the main advantages of defining Wasm exception types in JavaScript is that you need the exception type available when handling an exception in JavaScript. Having it defined in JavaScript saves you having to export it from the Wasm module.
So for example, you can start by constructing an error tag type like this:
You can then import it into a Wasm module like this:
Inside the Wasm module, you'd import the error tag and throw an exception of that type somewhere in your code:
Back in the JavaScript, you could then try running the exported throw() function in a try...catch statement. If the function throws, the error propagated to the catch block will be a WebAssembly.Exception object instance.
You can check whether it has the same exception type we defined earlier (myErrorTag) using Exception.prototype.is(), and then access the exception's payload using Exception.prototype.getArg()).
Note: You can't access the values of an exception with a new tag that just happens to have the same parameters; it's a different tag! This ensures that WebAssembly modules can keep exception information internal if required. Code can still catch and rethrow exceptions that it does not understand.
For a working example of handling a Wasm exception in JavaScript, see the throw instruction reference page.
This code snippet creates a new Tag instance:
The snippet below shows how we might import it into a Wasm module during instantiation:
The WebAssembly module might then import the tag as shown below:
If the tag was used to throw an exception that propagated to JavaScript, we could use the tag to inspect its values.
| WebAssembly JavaScript Interface: Exception Handling # tag |
Enable JavaScript to view this browser compatibility table.
This page was last modified on May 22, 2026 by MDN contributors.
Your blueprint for a better internet.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.