在使用以下简单代码测试节点服务器时,为什么会出现以下错误?
code/app2/i.js:35
throw new Error("here")
^
Error: here
根据《Smashing node.js》一书中的内容,我期望看到堆栈跟踪(点击获取该书)。下面是相关的第35页的图片:(点击查看):
* node uncaught-http-js
/uncaught-http.js:4
throw new Error("here");
^
Error: This will be uncaught
at Server.<anonymous> (/uncaught-http.js:4:9)
at Server.emit(events.js:70:17)
at HttpParser.onIncoming(http.js:1514:12)
at HttpParser.onHeadersComplete(http.js:102:31)
at Socket.andata (http.js:1410:22)
at TCP.onread(net.js:354:27)
但事实并非如此。
以下是代码。
function c () {
b();
};
function b () {
a();
};
function a () {
setTimeout(function () {
throw new Error('here');
}, 10);
};
c();
throw new Error('here')
明确地告诉 JavaScript 输出错误信息。你的问题基本上相当于:“我有alert('hi!')
,为什么这段代码会显示一个弹出框?!” - CrayonViolentnew
操作符是正确的。 - Sebastian SimonError: here
这行上面的两行是堆栈跟踪。 - Aify