获取 Windows Script Host 中运行的 JScript 中错误的行号
假设我有以下代码,使用 Windows 脚本宿主作为 .JS 文件运行:
try
{
ProduceAnError();
}
catch(e)
{
//How to get an error line here?
}
有什么方法可以知道发生错误(异常)的错误行吗?
Say, I have the following code that I run as a .JS file using the Windows Script Host:
try
{
ProduceAnError();
}
catch(e)
{
//How to get an error line here?
}
Is there any way to know the error line where an error (exception) occurred?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
抱歉我的其他回复。这不是很有帮助:P
我相信您正在寻找的是 ReferenceError 的堆栈属性。您可以使用传递给 catch:
示例输出的参数来访问它:
Sorry for my other reply. It wasn't very helpful :P
I believe what you are looking for is the ReferenceError's stack property. You can access it with the argument that you pass to the catch:
example output:
确实没有办法以编程方式获取堆栈甚至捕获行号。抛出错误时只能看到行号。您最多可以获得错误代码和描述,或者您可以自己犯错误。
这是文档。
举个例子
There isn't really a way to get a stack or even catch the line number programmatically. One can only see the line number when throwing an error. At best you can get the error code and description or you can make your own errors.
Here's the documentation.
And an example