Looking for an explanation for why when calling a function within a try-catch with no prefix await it is ignored
Example:
async function foo() {
try {
return bar()
} catch(e) {
throw new Error('never see this')
}
}
async function bar() {
throw new Error('only see this')
}
foo().then()
When adding await it does reach catch:
async function foo() {
try {
return await bar()
} catch(e) {
throw new Error('now this works')
}
}
async function bar() {
throw new Error('foo')
}
foo().then()
The strange thing is when calling a function that is not async the try-catch does work with no issues:
async function foo() {
try {
return bar()
} catch(e) {
throw new Error('now this works')
}
}
function bar() {
throw new Error('foo')
}
foo().then()