Javascript Node.js express 的 Error 对象暴露了哪些属性?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10624873/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What properties does Node.js express's Error object expose?
提问by shahalpk
I would like to know what are the functions the Error object of nodejs express exposes for use in Error Handling?
A console.log
of an error call new Error('NotFound')
is showing only [Error: NotFound]
, is this because .toString()
method is overriden? How do find the properties and functions exposed by these objects?
我想知道 nodejs express 的 Error 对象公开用于错误处理的功能是什么?错误调用的
A只显示,这是因为方法被覆盖了吗?如何找到这些对象公开的属性和功能?console.log
new Error('NotFound')
[Error: NotFound]
.toString()
回答by jmar777
The Error
object is actually a native object provided by V8
, rather than by node.js
or express
.
该Error
对象实际上是由 提供的本机对象V8
,而不是由node.js
或 提供的express
。
The property that will most likely be of the most use to you is stack
. E.g.,
最有可能对您最有用的属性是stack
。例如,
console.log(new Error('NotFound').stack);
There are other properties available as well, such as name
and message
. You can read up on them here. Just be aware that those docs are for Mozilla's JavaScript engine, so don't count on anything flagged as Non-standard
to work in node.js
.
还有其他可用的属性,例如name
and message
。你可以在这里阅读它们。请注意,这些文档适用于 Mozilla 的 JavaScript 引擎,因此不要指望任何标记为Non-standard
在node.js
.