Sniberb
Sniberb15mo ago

⛄Snowberb⛄ – 10-12 May 18

Why doesnt the try catch finally of this code respect the awaits, but if it is inside the (async () => {})() it does? I dont understand the syntax here
try {
(async () => {
if (!...) {
const ... = await ...;
...
return;
}
await ...
})();
} catch (e) {} finally {}
try {
(async () => {
if (!...) {
const ... = await ...;
...
return;
}
await ...
})();
} catch (e) {} finally {}
8 Replies
Sniberb
Sniberb15mo ago
The above doesnt work, but this does:
(async () => {
try {
if (!...) {
const ... = await ...;
...
return;
}
await ...
} catch (e) {} finally {}
})();
(async () => {
try {
if (!...) {
const ... = await ...;
...
return;
}
await ...
} catch (e) {} finally {}
})();
Eva
Eva15mo ago
Because you don't catch unawaited async functions
try {
await (async () => {
if (!...) {
const ... = await ...;
...
return;
}
await ...
})();
} catch (e) {} finally {}
try {
await (async () => {
if (!...) {
const ... = await ...;
...
return;
}
await ...
})();
} catch (e) {} finally {}
would work if IIFE throws something, you'd need another try catch inside of function to catch calls inside of it, obviously
Unknown User
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
Sniberb
Sniberb15mo ago
didnt understand
Eva
Eva15mo ago
first piece of code you sent can be simplified to
try {
asyncFunction();
catch (e) {} finally {}
try {
asyncFunction();
catch (e) {} finally {}
you don't await async function so if it throws you don't catch anything
Sniberb
Sniberb15mo ago
oh
Eva
Eva15mo ago
and it won't recursively catch anything within that function as well
reactibot
reactibot15mo ago
This thread hasn’t had any activity in 36 hours, so it’s now locked. Threads are closed automatically after 36 hours. If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/1108698568488927243