What properties does Node.js express's Error object expose?

自古美人都是妖i 提交于 2019-12-20 09:46:28

问题


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?


回答1:


The Error object is actually a native object provided by V8, rather than by node.js or express.

The property that will most likely be of the most use to you is stack. E.g.,

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.



来源:https://stackoverflow.com/questions/10624873/what-properties-does-node-js-expresss-error-object-expose

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!