⛄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 {}
S
Sniberb336d 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 {}
})();
E
Eva336d 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
UU
Unknown User336d ago
S
Sniberb336d ago
didnt understand
E
Eva336d 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
S
Sniberb336d ago
oh
E
Eva336d ago
and it won't recursively catch anything within that function as well
UU
Unknown User335d ago