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

141
Vistas
can't get an expect console output when using async await
    function fails4() {
      return new Promise((resolve, reject) => {
        setTimeout(function () {
          reject(new Error());
        }, 100);
      });
    }

    async function myFunc4() {
      try {
        await fails4();
      } catch (e) {
        console.log(e);
        console.log('that failed', e); //<-- this gets called
      }
    }
    async function loadmYScript() {
      try {
        await myFunc4();
      } catch (error) {
        console.log(error);
        console.log(123);
      }
    }
    loadmYScript();

cant't execute the console.log(123) as I expected can anybody help me with this question very appreciated

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You're calling loadmYScript, which in turn calls myFunc4, which in turn calls fails4. This last one (fails4) throws an error. The error is "catch-ed" by myFunc4. Inside this catch block you don't throw any error, there's only a couple of logs, so the result of loadmYScript is a fulfilled promise with undefined value. It is not rejected because myFunc4 doesn't throw the error.

If you throw an error inside the catch block of myFunc4, you will have your 123 logged, and the promise will be rejected.

about 4 years ago · Juan Pablo Isaza Denunciar
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