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.
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.
- What worse could happen with that method. File not exist. Don't seem logical to put it in try catch. – Prabodh M Commented Jun 28, 2017 at 11:51
2 Answers
Reset to default 6Looking 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;
}
};
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.