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

199
Vistas
Why error is not bubbled up if it's coming inside a promise without its catch block?

ok i'm asking this again, why the catch in the following code is not working as expected ? is this a design flaw of js ?

const getUserById = (id, authorized) => {
    return new Promise((resolve, reject) => {
        if (!authorized) {
            reject('Unauthorized access to the user data');
        }
        resolve({
            id: id,
            username: 'admin'
        });
    });
}

try {
    getUserById(10, false)
        .then(user => console.log(user.username));
    // the following code still executes ?
    console.log('next');

} catch (error) {
    console.log(`Caught by try/catch ${error}`);
}

Surprisingly, the catch didn't work.

The theory of try/catch block is catch should be able to caught all issues from try block. If we redesign JavaScript, can we make the catch in above code to work ?

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