GO-Ve01
ServicesDevelopersBooksDictionaryPapersWikidataEncyclopediaSearchBabelCareersDeck

WebAssembly.Exception.prototype.is()

The is() method of the Exception object can be used to test if the Exception matches a given tag.

The **`is()`** method of the [`Exception`](/docs/WebAssembly/Reference/JavaScript_interface/Exception) object can be used to test if the `Exception` matches a given tag.

The method might be used to test that a tag is correct before passing it to [`Exception.prototype.getArg()`](/docs/WebAssembly/Reference/JavaScript_interface/Exception/getArg) to get the passed values.
It can be used on tags created in JavaScript and those created in WebAssembly code and exported to JavaScript.

## Syntax

```js-nolint
is(tag)
```

### Parameters

- `tag`
- : A [`WebAssembly.Tag`](/docs/WebAssembly/Reference/JavaScript_interface/Tag) that can be checked to verify the type of the exception.

### Return value

A boolean value — `true` if the specified tag matches the exception, and `false` otherwise.

To return `true`, it is not enough for the tag to have an identical sequence of data types — it must have the same _identity_ (be the same tag) as was used to create the exception.

## Examples

The code below shows how to use `is()` to verify that a tag matches an [`Exception`](/docs/WebAssembly/Reference/JavaScript_interface/Exception).

```js
// Create tag and use it to create an exception
const tag1 = new WebAssembly.Tag({ parameters: ["i32", "f64"] });
const exception1 = new WebAssembly.Exception(tag1, [42, 42.3]);

// Verify that "tag1" matches this exception
console.log(`Tag1: ${exception1.is(tag1)}`);
```

This will log `Tag1: true` to the console.

We can also demonstrate that this exception will not match another tag even if the tag is created with the same parameters.

```js
// Create a new tag (with same parameters) and verify it does not match the exception
const tag2 = new WebAssembly.Tag({ parameters: ["i32", "f64"] });
console.log(`Tag2: ${exception1.is(tag2)}`);
```

This will log `Tag2: false` to the console.

For a full working example, see the [`throw`](/docs/WebAssembly/Reference/Exception_handling/throw) instruction reference page.

## Specifications

## Browser compatibility

## See also

- [WebAssembly](/docs/WebAssembly) overview
- [WebAssembly concepts](/docs/WebAssembly/Guides/Concepts)
- [Using the WebAssembly JavaScript API](/docs/WebAssembly/Guides/Using_the_JavaScript_API)

source: MDN Web Docs mirror · page

Cite this

"WebAssembly.Exception.prototype.is()". MDN Web Docs. CC BY-SA 2.5 (MDN). https://developer.mozilla.org/en-US/docs/WebAssembly/Reference/JavaScript_interface/Exception/is

JSON record · API collection · BibTeX · RIS · CSL-JSON · citation policy

Save to pass ·