Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Catching Node fs.existsSync errors

Does it make practical value to put fs.existsSync inside try...catch?

Is it possible that it will cause an error? How can this happen and which error would it be?

The reason I'm asking is because I'm trying avoid nested try...catch if possible.

like image 265
Estus Flask Avatar asked Dec 31 '25 10:12

Estus Flask


1 Answers

Looking at the (current) implementation, it doesn't make sense to wrap it with try...catch:

fs.existsSync = function(path) {
  try {
    handleError((path = getPathFromURL(path)));
    nullCheck(path);
    binding.stat(pathModule._makeLong(path));
    return true;
  } catch (e) {
    return false;
  }
};
like image 83
robertklep Avatar answered Jan 03 '26 11:01

robertklep



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!