Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

Promise.reject()

BaselineWidely available

ThePromise.reject() static method returns aPromise object that is rejected with a given reason.

Try it

function resolved(result) {  console.log("Resolved");}function rejected(result) {  console.error(result);}Promise.reject(new Error("fail")).then(resolved, rejected);// Expected output: Error: fail

Syntax

js
Promise.reject(reason)

Parameters

reason

Reason why thisPromise rejected.

Return value

APromise that is rejected with the given reason.

Description

The staticPromise.reject function returns aPromise that is rejected. For debugging purposes and selective error catching, it is useful to makereason aninstanceofError.

Promise.reject() is generic and supports subclassing, which means it can be called on subclasses ofPromise, and the result will be a promise of the subclass type. To do so, the subclass's constructor must implement the same signature as thePromise() constructor — accepting a singleexecutor function that can be called with theresolve andreject callbacks as parameters.Promise.reject() is essentially a shorthand fornew Promise((resolve, reject) => reject(reason)).

UnlikePromise.resolve(),Promise.reject() always wrapsreason in a newPromise object, even whenreason is already aPromise.

Examples

Using the static Promise.reject() method

js
Promise.reject(new Error("fail")).then(  () => {    // not called  },  (error) => {    console.error(error); // Stacktrace  },);

Rejecting with a promise

UnlikePromise.resolve, thePromise.reject method does not reuse existingPromise instances. It always returns a newPromise instance that wrapsreason.

js
const p = Promise.resolve(1);const rejected = Promise.reject(p);console.log(rejected === p); // falserejected.catch((v) => {  console.log(v === p); // true});

Calling reject() on a non-Promise constructor

Promise.reject() is a generic method. It can be called on any constructor that implements the same signature as thePromise() constructor. For example, we can call it on a constructor that passes itconsole.log asreject:

js
class NotPromise {  constructor(executor) {    // The "resolve" and "reject" functions behave nothing like the    // native promise's, but Promise.reject() calls them in the same way.    executor(      (value) => console.log("Resolved", value),      (reason) => console.log("Rejected", reason),    );  }}Promise.reject.call(NotPromise, "foo"); // Logs "Rejected foo"

Specifications

Specification
ECMAScript® 2026 Language Specification
# sec-promise.reject

Browser compatibility

See also

Help improve MDN

Learn how to contribute.

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp