Sniberb
Sniberb2y 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
SniberbOP2y 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
Eva2y 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 User2y ago
Message Not Public
Sign In & Join Server To View
Sniberb
SniberbOP2y ago
didnt understand
Eva
Eva2y 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
SniberbOP2y ago
oh
Eva
Eva2y ago
and it won't recursively catch anything within that function as well
reactibot
reactibot2y 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