admin管理员组文章数量:1313121
In Chrome, when an exception occurs, it prints a stack trace to the console log. This is extremely useful, but unfortunately in cases where an exception has been rethrown this causes an issue.
} catch (e) {
if (foo(e)) {
// handle the exception
} else {
// The stack traces points here
throw e;
}
}
Unfortunately, the following code in jQuery.js
is causing all exceptions to have this issue if they're from inside event handlers.
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;
}
Is there a way to change the throw e;
so that the exception is rethrown with the same stack trace?
In Chrome, when an exception occurs, it prints a stack trace to the console log. This is extremely useful, but unfortunately in cases where an exception has been rethrown this causes an issue.
} catch (e) {
if (foo(e)) {
// handle the exception
} else {
// The stack traces points here
throw e;
}
}
Unfortunately, the following code in jQuery.js
is causing all exceptions to have this issue if they're from inside event handlers.
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;
}
Is there a way to change the throw e;
so that the exception is rethrown with the same stack trace?
- 3 Possible duplicate of How can I rethrow an exception in Javascript, but preserve the stack? – cmroanirgo Commented Jan 2, 2017 at 3:00
2 Answers
Reset to default 4This is a known bug in Chrome, and unfortunately there's no workaround that I'm aware of.
The best you can do is grab the original stack and print it. I use this in unit testing tools.
try{
...
}
catch(e){
console.log(e.stack);
console.log(e.message);
throw(e);
}
本文标签: JavaScript rethrowing an Exception preserving the stack traceStack Overflow
版权声明:本文标题:JavaScript rethrowing an Exception preserving the stack trace - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741925176a2405239.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论