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

186
Vistas
Ignoring the Error object in try-catch in the correct way

I have the following code snippet:

try{
   client.close();
 }catch(e){}

where I try to catch an exception without using the Error object. Is there a more eloquent/better way in JavaScript? Maybe something like:

try{ client.close(); }
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Depending of your needs, maybe useful something like this:

let ignoreException = (callback) => {
  try {
    callback();
  }
  catch(e)
  {   
  }
}

You can ignore exceptions in a single line of code:

ignoreException(() => tag.style.backgroundColor = "yellow");
ignoreException(() => tag.styleNotExists.backgroundColor = "yellow");

Check a sample here: https://jsfiddle.net/0cmdvo38/1/

about 4 years ago · Juan Pablo Isaza Denunciar

0

With Javascript MDN documentation, you use try ... finally

try {
  writeMyFile(theData);
} finally {
  closeMyFile(); // whatever happened up there, always run this
}
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