Allows you to specify work to be done on the rejection of a promise.
Syntax
promise.catch(onRejected)
Parameters
promise
Required. The promise object.
onRejected
Required. The error handler function to run when a promise is rejected.
Remarks
Example
In the following code example, the first call to timeout returns after 5000ms. In this code, the promise is rejected, and the error handler function runs.
function timeout(duration) {
return new Promise(function(resolve, reject) {
setTimeout(reject, duration);
});
}
var p = timeout(5000).then(() => {
console.log("done!");
}).catch(err => {
console.log("error!");
})
// Output (after five seconds):
// error!
Requirements
Supported in Microsoft Edge (Edge browser). Also supported in Store apps (Microsoft Edge on Windows 10). See Version Information.
Not supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards, Internet Explorer 10 standards, Internet Explorer 11 standards. Not supported in Windows 8.1.

