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

266
Views
How to catch an asynchronous error in JavaScript

Is there a way to ignore asynchronous errors while calling a function?

Synchronous

function synchronous() {
    console.log('Nice feature');
    throw new Error('Async Error');
}

try {
    synchronous();
    console.log('Succeeded');
} catch (e) {
    console.log('Caught');
}

Console Output:
Nice feature
Caught

Asynchronous

async function asynchronous() {
    console.log('Nice feature');
    throw new Error('Async Error');
}

try {
    asynchronous();
    console.log('Succeeded');
} catch (e) {
    console.log('Caught');
}

Console Output:
Nice feature
Uncaught (in promise) Error: Async Error at asyncFunc

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

two options:

(async () => {
  try {
    await asynchronous();
    console.log('Succeeded');
  } catch (e) {
    console.log('Caught');
  }
});

or

 asynchronous()
       .then(r => {
         console.log('succeeded');
       })
       .catch(e => {
           console.log('caught');
         });
about 4 years ago · Juan Pablo Isaza Report

0

I'm not sure if that answers your question, but if "await" for the result of calling asynchronous() function, the error will not occur

about 4 years ago · Juan Pablo Isaza Report
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!