Reputation: 222865
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.
Upvotes: 2
Views: 2754
Reputation: 456
fs.existsSync
cannot throw
an error.
Here is the implementation of fs.existsSync
, in which try..catch
es its own errors and returns false
when an error occurs.
Upvotes: 5
Reputation: 203494
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;
}
};
Upvotes: 6