Home Async/Await while avoiding the Try/Catch block?
Reply: 1

Async/Await while avoiding the Try/Catch block?

Ivan Drenjanin
1#
Ivan Drenjanin Published in 2018-01-12 09:29:18Z

I've been working with Node for about month or so and I wanted to utilize the latest features available, like Async/Await style, but I do not like using the try/catch blocks with it. I have been trying to make some kind of a wrapper class and/or functions to wrap the async/await, which can be seen on the following link: https://repl.it/@Zaramao/AsyncAwait-Test

I used the destructuring logic of await-to-js npm module to mitigate the usage of try/catch partially, but I am somewhat confused on how would I use it outside of an async function without using es6 promises, and how could I chain multiple awaits using this approach?

Any help, suggestion or critics, if I am doing something completely wrong, is more than appreciated.

Aminadav
2#
Aminadav Reply to 2018-01-12 09:35:45Z

You have to choose. Using try, catch block, or use promises. The reason for async/await exist, is for people who do not like promises, and prefer cleaner code.

If you don't want both, you can use

https://nodejs.org/api/process.html#process_event_uncaughtexception

or

https://nodejs.org/api/process.html#process_event_unhandledrejection

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.321129 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO