Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

116
Views
Why try catch is ignored when returning an async function with no await prefix

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()
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!