所以我一直在使用 Visual Studio 的 Node.js 工具 ( https://nodejstools.codeplex.com )。
我有这个反复出现的问题,当出现异常时它总是会开始调试。这听起来像是一件好事但当异常应该被捕获时就不是这样了!
以此为例(这是来自bson模块)
try {
// Load the precompiled win32 binary
if(process.platform == "win32" && process.arch == "x64") {
bson = require('./win32/x64/bson');
} else if(process.platform == "win32" && process.arch == "ia32") {
bson = require('./win32/ia32/bson');
} else {
bson = require('../build/Release/bson');
}
} catch(err) {
console.error("Failed to load c++ bson extension, using pure JS version");
bson = require('../lib/bson/bson');
}
这里将在使用纯 JS 版本被捕获之前进入调试,这是预期的行为,但我希望 VS 避免在之后被捕获时启动调试...(这清楚吗?)
我的临时解决方案是转到 Debug/Exceptions/Node.js Exceptions 并为 Error 下的所有内容取消选中“Thrown”...但是当我遇到真正需要抛出的错误时,调试器不会选择它们.
也许这只是工具的局限性,因为它很新,但如果其他人找到了解决方案,那将非常有帮助!
最佳答案
NTVS currently reports all exceptions whenever they are thrown - we can't determine whether they're caught somewhere up the stack. Those missing module exceptions are virtually always caught. For the time being, you can add this exception type to Debug -> Exceptions, and disable breaking on it, if you don't want to press F5 every time to move on. In the upcoming beta release, this setting will be there by default.
关于用于 Visual Studio 的 Node.js 工具总是在出现异常时停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22676142/