Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

187
Views
Ignorando el objeto Error en try-catch de la manera correcta

Tengo el siguiente fragmento de código:

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

donde trato de detectar una excepción sin usar el objeto Error. ¿Hay una forma más elocuente/mejor en JavaScript? Tal vez algo como:

 try{ client.close(); }
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Dependiendo de sus necesidades, tal vez sea útil algo como esto:

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

Puede ignorar las excepciones en una sola línea de código:

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

Consulte una muestra aquí: https://jsfiddle.net/0cmdvo38/1/

about 4 years ago · Juan Pablo Isaza Report

0

Con la documentación de Javascript MDN , usas try ... finally

 try { writeMyFile(theData); } finally { closeMyFile(); // whatever happened up there, always run this }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!