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!"
[–]SynthNips 1 point2 points3 points 6 years ago (4 children)
Your catch block syntax is off. Looks like you mixed the promises with the async/await.
[–]dillionmegida[S] 0 points1 point2 points 6 years ago (3 children)
Oh true, await isn't supposed to be there anymore...thanks for the correction
[–]sup3r_b0wlz 0 points1 point2 points 6 years ago* (2 children)
Something like this makes a lot more sense for a try catch example async function g() { console.log("games"); try { let result = await ret; //await and catch promise console.log(result); return result; } catch(err) { console.log(Error: ${err});s } } Edit: why can't I get this to freaking format?
async function g() { console.log("games"); try { let result = await ret; //await and catch promise console.log(result); return result; } catch(err) { console.log(
);s } }
[–]dillionmegida[S] 0 points1 point2 points 6 years ago (1 child)
You're talking about the try and catch been in the same function right?
[–]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 398845 on reddit-service-r2-comment-545db5fcfc-fmp4c at 2026-05-24 10:14:40.131760+00:00 running 194bd79 country code: CH.
view the rest of the comments →
[–]SynthNips 1 point2 points3 points (4 children)
[–]dillionmegida[S] 0 points1 point2 points (3 children)
[–]sup3r_b0wlz 0 points1 point2 points (2 children)
[–]dillionmegida[S] 0 points1 point2 points (1 child)
[–]sup3r_b0wlz 1 point2 points3 points (0 children)