Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

289
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda