I’m trying to get useful information from the exception object (passed to the a “catch”) and it is nearly empty in chrome. I have used it before and was able to get a reasonable stack trace, among other things. Is this a change to chrome, or am I doing something wrong? I’m doing this:
function pr(s) {
document.body.innerHTML += s.toString() + "<br>";
}
function test() {
try {
var a = b; // err: b not defined
} catch (ex) {
pr('==== print exception object =====');
pr(ex);
pr('======= typeof exception object =====');
pr(typeof ex);
pr('===== members ======');
for (var i in ex) {
pr(' ----- ' + i + " ------");
pr(ex[i]);
}
console.log(ex);
}
}
function first() {
second();
}
function second() {
test();
}
first();
In Chrome it gives me nothing more than the string “ReferenceError: b is not defined” if I do a toString() on the exception object, but if I try to look at the object’s individual members, there is nothing there. Notably there is no “stack” member. Then again, if looked at in the console, there is more there (but the stack is simply “-“)
That hyphen means it’s a getter, and is not automatically executed because it could have side effects. You can log them separately however: http://jsfiddle.net/R9Wkg/1/.
The fact that the error isn’t enumberable is filed as an issue at V8’s project site.