4 ms·
> However, I recently started using async/await in TypeScript, and the result seems to be try/catch statements everywhere. Why do you have try/catch everywhere
by koolba 9y ago
> However, I recently started using async/await in TypeScript, and the result seems to be try/catch statements everywhere.
Why do you have try/catch everywhere? Unless you're actually going to handle the error, you shouldn't do anything as it will bubble up till it gets to a piece of the app that can handle it. For web apps a lot of the time that's a single request level handler to return a 5XX.
> Code using async/await seems to be more verbose and unruly than just sticking to Promises, which I now appreciate the elegance of much more (callee convenience/error delegation).
Eh? Besides the addition of the "async" keyword on the top level function, it's always less verbose.
Where I think things get a bit tricky is awaiting the composition of Promises to support parallel processing (as opposed to just 1) await foo() 2) await bar() ...). It's best to treat that like regular composition and simply await the result.