为什么node.js打印错误的堆栈跟踪?

时间:2016-10-30 20:38:13

标签: javascript node.js

为什么每当创建Error对象(而不是抛出)时,node.js就会在REPL中打印堆栈跟踪?其他REPL默认情况下似乎没有这种行为,我看不到它的用例。

有没有办法抑制这种行为?

的Python:

$ python
Python 2.7.11 (default, Jan 22 2016, 08:29:18)
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> Exception('something bad happened')
Exception('something bad happened',)

节点:

$ node
> new Error('something bad happened')
Error: something bad happened
    at repl:1:1
    at sigintHandlersWrap (vm.js:22:35)
    at sigintHandlersWrap (vm.js:96:12)
    at ContextifyScript.Script.runInThisContext (vm.js:21:12)
    at REPLServer.defaultEval (repl.js:313:29)
    at bound (domain.js:280:14)
    at REPLServer.runBound [as eval] (domain.js:293:12)
    at REPLServer.<anonymous> (repl.js:504:10)
    at emitOne (events.js:101:20)
    at REPLServer.emit (events.js:188:7)

铬:

new Error('something bad happened')
Error: something bad happened(…)

0 个答案:

没有答案