如何使用Javascript获取错误行号和行文本 [英] How to get Error Line number and line text using Javascript

查看:565
本文介绍了如何使用Javascript获取错误行号和行文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尊敬的先生,

如何使用Javascript获取错误行号和行文本

请知道的人告诉我如何?

预先感谢.

Dear sir,

How to get Error Line number and line text using Javascript

please anybody known tell me how?

Thanks in advance.

推荐答案

我可以给你这个主意.

您可以通过分析异常对象的成员.stack的值来做到这一点:

I can give you just the idea.

You can do it from analysis of the value of the member .stack of the exception object:

function ProcessExceptionInformation(message, stack) {
    // extract position information from stack
    // output or log the exception information as required
}

//...

<pre lang="JavaScript">try {
    //do something
} catch(e) {
    ProcessExceptionInformation(e.message, e.stack);
}



—SA



—SA



要检查发生错误的位置,您可以使用诸如firebug(带有firefox)之类的工具来调试javascript
对于具有最新浏览器的IE,您可以通过按F12键使用开发人员工具

To check where error occurs you can use tool, like firebug(with firefox)to debug javascript
for IE with latest browser you can use developer tool by pressing F12


这篇关于如何使用Javascript获取错误行号和行文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆