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

137
Vistas
rejected promise not catched neither inside nor outside async function

I get UnhandledPromiseRejection when i run the following code on node.js v17.1.0. The "awaited" rejectAfter100ms promise is not catched neither by the surrounding "trycatch" inside the async function nor by "then" method on the returned promise.

Why such behaviour? Any explanation coming from the specification?

const asyncFunc = async () => {
  const resolveAfter2000ms = new Promise((resolve) => {
    setTimeout(resolve, 2000);
  });
  const rejectAfter100ms = new Promise((_, reject) => {
    setTimeout(reject, 100);
  });

  try {
    await resolveAfter2000ms;
    await rejectAfter100ms;
  } catch (error) {
    console.log('error catched inside async');
  }
};

asyncFunc().catch(() => console.log('error catched outside async'));
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