[英]Catching Node fs.existsSync errors
Does it make practical value to put fs.existsSync
inside try...catch
? 将
fs.existsSync
放入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. 我问的原因是因为我试图避免嵌套
try...catch
如果可能的话。
Looking at the (current) implementation , it doesn't make sense to wrap it with try...catch
: 看看(当前)实现 ,用
try...catch
包装它是没有意义的:
fs.existsSync = function(path) {
try {
handleError((path = getPathFromURL(path)));
nullCheck(path);
binding.stat(pathModule._makeLong(path));
return true;
} catch (e) {
return false;
}
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.