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

185
Views
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 answers
Answer question

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 Report

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 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!