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(); }
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/
With Javascript MDN documentation, you use try ... finally
try {
writeMyFile(theData);
} finally {
closeMyFile(); // whatever happened up there, always run this
}