3 ms·
Another commenter pointed out that .catch is perfectly fine in the async/await world, even though you pretty much never use .then anymore. Here's another way of
by brlewis 7y ago
Another commenter pointed out that .catch is perfectly fine in the async/await world, even though you pretty much never use .then anymore. Here's another way of doing it:
try {
doSomething(await funcThatReturnSomeType());
} catch (err) {
doSomethingWithErr(err);
}
- Jasper_ 7y agoThey're not equivalent if doSomething might throw and you don't want to catch it.
- brlewis 7y agoRight, which goes back to the question shtylman asked about why doSomething couldn't be part of the try block. I'm tossing this form out there in case it helps. People sometimes forget that await can go wherever an expression goes.