说,我有以下代码,我使用
Windows脚本宿主作为.JS文件运行:
try { ProduceAnError(); } catch(e) { //How to get an error line here? }
解决方法
对不起我的其他回复.这不是很有帮助:P
我相信你要找的是ReferenceError的堆栈属性.您可以使用传递给catch的参数来访问它:
try { someUndefinedFunction("test"); } catch(e) { console.log(e.stack) }
示例输出:
ReferenceError: someUndefinedFunction is not defined at message (http://example.com/example.html:4:3) at <error: TypeError: Accessing selectionEnd on an input element that cannot have a selection.> at HTMLInputElement.onclick (http://example.com/example.html:25:4)