[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Error/cause [Back]  [Original]

Error: cause - JavaScript | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

Error: cause

Baseline Widely available

This feature is well established and works across many devices and browser versions. Its been available across browsers since 2021 9.

Error cause .

.

In this article

options.cause Error() . .

Property attributes of Error: cause

. catch Error cause Error . " " cause .

cause

. Error .

js
try {
  connectToDatabase();
} catch (err) {
  throw new Error("Connecting to database failed.", { cause: err });
}

Error > Differentiate between similar errors .

. . , .

js
function makeRSA(p, q) {
  if (!Number.isInteger(p) || !Number.isInteger(q)) {
    throw new Error("RSA key generation requires integer inputs.", {
      cause: { code: "NonInteger", values: [p, q] },
    });
  }
  if (!areCoprime(p, q)) {
    throw new Error("RSA key generation requires two co-prime integers.", {
      cause: { code: "NonCoprime", values: [p, q] },
    });
  }
  // rsa algorithm
}

Specification
ECMAScript 2027 LanguageSpecification
# sec-installerrorcause


Web Proxy Viewer  |  New URL  |  Original Page