Better way to rethrow errors for debugging javascript in Chrome -
the chrome debugging tools great of time, lately i've been annoyed errors rethrown. there doesn't seem way see call stack unless have set pause on caught exceptions, run gobs of errors other libraries. makes pausing on exceptions pretty useless if want display errors nicely.
consider example (http://jsfiddle.net/redbmk/83y8l/1/):
html:
<button id="push-me"></button>
javascript:
function bedangerous() { var 1 = 1, rand = parseint(math.random() * 2); if (rand === one) console.log("you win"); else if (rand === zero) console.log("you lose"); } function warnuser(error) { alert("hey, went wrong! refresh page"); throw error; } function runcode() { try { bedangerous(); } catch (e) { warnuser(e); } } document.getelementbyid("push-me").addeventlistener("click", runcode);
when run error, call stack shows warnuser
threw error , called runcode
. there's no way trace bedangerous , see variables @ point. can see stack trace, looking @ error.stack
, , doesn't give context. replacing throw error
debugger
doesn't seem (and wouldn't allow turn off debugging).
is there better way this? it's been bugging me while now.
by way, this question says throw error.stack
, doesn't work me (and understand stack
property non-standard anyway, wouldn't work correctly other browsers). this question says it's known bug in chrome marked being fixed in version 19, happening me on version 35.
this different, known bug in chrome, unfortunately, marked wontfix. looks firefox dev tools have same problem too.
Comments
Post a Comment