DEV Community

Discussion on: Async/Await with easy to understand examples.

Collapse
lukeshiru profile image
LUKESHIRU • Edited on

For those wondering how the try/catch example looks without async/await, and just using promises:

const asyncTask = () =>
    new Promise((_resolve, reject) =>
        setTimeout(() => reject("Something not working!"), 1e3)
    );

const foo = () =>
    asyncTask()
        .then(console.log)
        .catch(console.error)
        .finally(() => console.log("After calling AsyncTask"));

foo();
Enter fullscreen mode Exit fullscreen mode

I also used console.error instead of console.log for the error.

Cheers!

Collapse
nehal_mahida profile image
Nehal Mahida Author

Hey mate, Thanks for additional info 🤗

Happy Coding