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

209
Vistas
How to "catch" console.error()? (SO title)

I included a lib that uses console.error() instead of throw.

Because of this, my try...catch doesn't work. And because it's a 3rd party lib, I can't change their code.

Is there a (preferably elegant) workaround to "catch" a console.error()?

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

0

You cannot catch something that doesn't throw any errors. It looks like a crutch but you can override your console.error method in the code below. But don't forget that after you will have overriden console.error that throws errors!!!

console.errorWithoutExceptions = console.error;
console.error = (...messages) => {
    console.errorWithoutExceptions(...messages); 
    throw new Error(messages[0]);
}

// now you can use 
try {
   // your code
   console.error('test error');
} catch(e) {
   // process you error with message 'test error' here
}

// don't forget to restore previous console.error after using
console.error = console.errorWithoutExceptions;

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can try and manipulate the global console object to your requirement. But that's messy and might generate additional errors.

More here : Console | Node.js Docs

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