To begin with, I am taking a follow up from this question I posted few moments ago
Now, I thought I knew Aysnc and Promise but clearly I am missing something.
Referencing to the Tagged answer by estus,
Unless API supports promises, errors should be entirely handled in async function. Function body should be wrapped with try..catch to rule out unhandled rejections which may result in exceptions in future Node versions
From which I was able to comprehend that whenever we are using aysnc function and we want to do error Handling we need to use try..catch
and for normal Promises we could simple do resolve/reject or if it is already a promise then we can chain and do .then
and .catch
but for that I got following reply on comment
Yes, you can expect an error. async/await is just syntactic sugar for raw promises. Any async function can be rewritten in plain ES6
I might be keeping this question broad but can someone please help me in explaining..
When do we need to use
.then
and .catch
and when do we need to use
try..catch
Also, What does it mean by
Unless API supports promises