Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

197
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda