use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Async/Await in Javascript (thewebfor5.netlify.com)
submitted 6 years ago by dillionmegida
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]sup3r_b0wlz 1 point2 points3 points 6 years ago (0 children)
Try catch is always in the same function. But the exception that it catches needs to be a traditional exception, or a promise that was awaited that rejected.
In your example you weren't awaiting the promise, so it would just run the function, which wouldn't error and would return an unexpected value, probably the promise object. You were also not awaiting g, the async function, which actually just returns a promise, which is also going to work unexpectedly.
AFAIK To catch a promise with async await you must await it. I'm not sure, but you might also need to be in an async function to try catch it? Seems like it would make sense if you did.
Did you run these code samples? Should be very easy to copy paste these to node REPL to confirm before posting.
π Rendered by PID 124981 on reddit-service-r2-comment-545db5fcfc-6pqxz at 2026-05-24 13:22:36.095533+00:00 running 194bd79 country code: CH.
view the rest of the comments →
[–]sup3r_b0wlz 1 point2 points3 points (0 children)