catch()

ES6+

Attaches a rejection handler callback to the promise.

Syntax

promise.catch(onRejected)

Parameters

onRejected Function

A function called when the Promise is rejected

Return Value

Promise

A new Promise

Examples

JavaScript
Promise.reject(new Error('실패!'))
  .catch(error => {
    console.log(error.message);
  });
Output:
// '실패!'

Related Methods