Javascript 正在捕获节点fs.existsSync错误
将Javascript 正在捕获节点fs.existsSync错误,javascript,node.js,Javascript,Node.js,将fs.existsSync放入try…catch中是否具有实用价值 是否可能会导致错误?这是怎么发生的,会是什么错误 我问这个问题的原因是,如果可能的话,我试图避免嵌套的try…catch。看,用try…catch来包装它是没有意义的: fs.existsSync = function(path) { try { handleError((path = getPathFromURL(path))); nullCheck(path); binding.stat(pat
fs.existsSync
放入try…catch
中是否具有实用价值
是否可能会导致错误?这是怎么发生的,会是什么错误
我问这个问题的原因是,如果可能的话,我试图避免嵌套的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;
}
};
fs.existsSync
无法抛出错误
是fs.existsSync
的实现,其中try..catch
会在发生错误时删除自己的错误并返回false
。该方法可能会发生更糟糕的情况。文件不存在。把它放在试一试中似乎不合逻辑。