在Chrome中从控制台运行代码时获取堆栈跟踪错误 [英] Getting stack trace for an error when running code from the console in Chrome
问题描述
我从控制台调用一个函数,但是当它抛出一个异常时,我没有收到类似于代码正常执行的堆栈跟踪。
是有一种方法可以修改我的命令(也许用try / catch)让它提供这些信息吗?
澄清: page.js: page.js 我没有收到返回给我的错误的行号。当从页面(而不是控制台)运行它时,我会收到一个行号和一个堆栈跟踪。 虽然详细,但会在Chrome JS控制台中打印交互式错误的堆栈跟踪: 不幸的是,如果非 I am calling a function from the console but when it throws an exception I do not receive a stack trace like I would if the code was executed normally. Is there a way I can modify my command (perhaps with try/catch) to have it provide me this information? to clarify: page.js: console, after loading a html page that links page.js I get no line number from the Error that is returned to me. When running it from the page (instead of the console) i would receive a line number and a stack trace. Although verbose, this will print the stack trace of an interactive error in the Chrome JS console: Unfortunately this won't work if a non- 这篇关于在Chrome中从控制台运行代码时获取堆栈跟踪错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
function otherStuff(){return ['a','b',undefined,'c'];
函数doStuff(){
var x = otherStuff();
var z = parseInt(x [2]); //这将会抛出一个错误
}
>其他的东西();
try {
throw new Error();
} catch(e){
console.error(e.stack);
}
错误
对象被抛出。function otherStuff() { return ['a','b',undefined,'c'];
function doStuff() {
var x = otherStuff();
var z = parseInt(x[2]); // this will throw an error
}
> otherStuff();
try {
throw new Error();
} catch (e) {
console.error(e.stack);
}
Error
object is thrown.