JavaScript异常处理-显示行号 [英] JavaScript exception handling - displaying the line number

查看:43
本文介绍了JavaScript异常处理-显示行号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在JavaScript中捕获/处理异常时,如何确定异常发生时的调用堆栈?(以及行号(如果可能的话))

When catching / handling exceptions in JavaScript, how can I determine what the call stack was when the exception occurred? (and also if possible what the line number was)

try
{
    // etc...
}
catch (ex)
{
    // At this point here I want to be able to print out a detailed exception 
    // message, complete with call stack, and if possible line numbers.
}

推荐答案

每个浏览器对此的处理方式都不相同,因此没有通用的方法可以做到这一点.此博客文章具有一些不错的代码,可以为大多数受支持的浏览器转储堆栈跟踪.我认为没有提供行号的好方法.

Each browser handles this differently, so there isn't a universal way to do it. This blog post has some good code to dump a stack trace for most supported browsers. I don't think there is a good way to provide the line number.

如果您要特别调试一个功能,则 Firebug 具有良好的堆栈跟踪功能(vis console.trace()).

If you're looking to debug one function in particular, Firebug has a good stack trace function (vis console.trace()).

这篇关于JavaScript异常处理-显示行号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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