How should I handle an error that is thrown from a promise, in the catch block?
For instance,
try {
// some other functions/code that can also throw error
var promise = // a service that returns new Promise() object
promise.then(function(data) {
//some business logic
}, function(err) {
throw new Error(err); // never gets caught in catch block
});
} catch(error) {
// do something with error
console.log(error);
}
1) Is it possible to handle an error in try catch block thrown from promise?
2) Is there some better approach to handling common error?