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

286
Views
JavaScript: Catching an error thrown in a promise does not work?

I read somewhere that it should be possible to catch an error that was thrown in the promise using Promise.catch, but I'm not quite getting it to work..

Here is a minimal working(or not) example I'm having issues with. I've tried to catch the error using try-catch and using Promise.catch, but neither of them seem to work. Am I missing something here?

{
function throwingFunction() {
    return new Promise(() => {
        setTimeout(() => {
            throw new Error();
        }, 1000);
    })
}
(async() => {
    try {
        await throwingFunction().catch(error => console.log("then-catch"));
    } catch(error) {
        console.log("try-catch");
    }
})()

}

The problem I am trying to solve is the following: I'm writing some tests for an application. The application throws some errors that I can then use as feedback when testing the ui.

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!