Reputation: 77
I am sort of novice to JS and experimenting how the things work. How can I output error in the following case:
var k =Promise.resolve(function(){
return new Promise((resolve,reject)=>reject("Error"))
});
k.then(...)
Upvotes: 1
Views: 37
Reputation: 1
You can add a catch()
block after then.
The catch()
method returns a Promise
and deals with rejected cases only. It behaves the same as calling Promise.prototype.then(undefined, onRejected)
. See here for more
var k =Promise.resolve(function(){
return new Promise((resolve,reject)=>reject("Error"))
});
Like this
k.then(...).catch((error)=>{
console.log(error)
})
Upvotes: 1