I have an async function that I expect to throw an exception. However, something is stopping this:
Omitting the catch try blocks, I expect an exception to be thrown that I want to handle outside the function.
The actual result that I get is somewhat confusing:
(node:10636) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): E11000 duplicate key error index.
(node:10636) 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.
async f(obj) {
await db.collection('...').save(obj);
}
I get the same result when I try to catch an exception and instead another one is imposed instead:
async f(obj) {
try {
await db.collection('...').save(obj);
} catch(e) {
throw e.message;
}
}
The function is called from the try block, so you cannot see how this is Unhandled Promise.
I am trying to use fanother function as a parameter:
g(obj, handler) {
try {
handler(obj);
} catch(e);
...
}
}
g(objToSave, f);
source
share