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

196
Views
Unhandled promise rejection but using .catch()

When call a throw from async function node says an error:

Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch().

But i have a .catch() defined on call:

class Cls {
    async fn(){
        throw new Error('err');
        return 'test';
    }
}

cls = new Cls();
cls.fn()
.then(data => console.log(data))
.catch(e => { throw e })

What is the problem?

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

0

The catch here

cls.fn()
.then(data => console.log(data))
.catch(e => { throw e })

is actually catching an error thrown inside the fn method.:

  throw new Error('err');

However, after you catch it, you explicitly raise another error

.catch(e => { throw e });

And now there's no one to capture this new error you throw, so your program crashes.

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!