在Chrome中,发生异常时,它会将堆栈跟踪打印到控制台日志。这非常有用,但不幸的是,在重新抛出异常的情况下,这会导致问题。JavaScript重新抛出异常保留堆栈跟踪
} catch (e) {
if (foo(e)) {
// handle the exception
} else {
// The stack traces points here
throw e;
}
}
不幸的是,在jQuery.js
下面的代码是导致所有的异常,如果他们从内部事件处理程序是有这个问题。
try {
while(callbacks[ 0 ]) {
callbacks.shift().apply(context, args);
}
}
// We have to add a catch block for
// IE prior to 8 or else the finally
// block will never get executed
catch (e) {
throw e;
}
finally {
fired = [ context, args ];
firing = 0;
}
有没有办法来改变throw e;
使异常与同一堆栈跟踪重新抛出?
的可能重复[我怎样才能重新引发在Javascript例外,但保留堆栈?](http://stackoverflow.com/questions/3734236/how-can-i-rethrow-an-exception-在JavaScript中但是保留堆栈) – cmroanirgo