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

288
Visualizações
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
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