I have a promise and I would like an exception to be thrown if the promise is rejected. I tried this:
var p = new Promise( (resolve, reject) => {
reject ("Error!");
} );
p.then(value => {console.log(value);});
but I get a DeprecationWarning:
(node:44056) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): Error!
(node:44056) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
What is the correct way to throw an error (so that the program is terminated with a stack trace) if the promise is rejected?
I already tried to insert a throw statement in a catch clause, but this again produces a DeprecationWarning as before. In fact (after some reading) I understand that a throw in a catch produce another call to the reject callback.