Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

DataCloneError DOMException — data cloning failure

DataCloneError is the name of a DOMException indicating that data cannot be cloned. Learn a typical cause in structuredClone(), how to recognize the error, and why an unsupported value differs from a supported circular reference.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

structuredClone(value)
structuredClone(value, options)
error.name === "DataCloneError"

DataCloneError DOMException means a DOMException object whose name is "DataCloneError", not a separate DataCloneError constructor. Its legacy code is 25 (DATA_CLONE_ERR); identify the error through name, not the obsolete numeric code.

structuredClone() throws this exception synchronously when any part of the data being cloned is not structured-serializable. Functions and DOM nodes are unsupported, including inside an ordinary object. Circular references alone do not cause failure: the algorithm can preserve them. This algorithm is also used to send data through postMessage() between Workers and to store values in IndexedDB.

In the example, task contains a function, so the first clone throws. The catch handles only the expected error and rethrows anything else. The second clone selects data only. Pass supported values instead of functions or DOM nodes. Do not make the test depend on the full message text.

This is a Web API mechanism, not a feature assigned to a particular ECMAScript edition. MDN reports cross-browser availability of structuredClone() since March 2022; check compatibility for your target environment. Having Node 24 in a repository does not prove browser API support.

Examples

const value = { count: 3, task: () => 42 };

try {
  structuredClone(value);
} catch (error) {
  if (!(error instanceof DOMException) || error.name !== "DataCloneError") {
    throw error;
  }
  console.log(error.name);
}

const copy = structuredClone({ count: value.count });
console.log(copy.count);

Result

DataCloneError
3

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources