Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
261 views
in Technique[技术] by (71.8m points)

javascript - When will proper stack traces be provided on window.onError function?

Exceptions/Errors in many other programming languages (say java, ruby) always provide stacktrace/backtrace information.

In JavaScript unhandled Errors get caught by window.onError.

Although that function does not get the Error object, so we have no access to the object's stack property.

Is there any reliable source of information about when will there be any change on that?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The error object, which would contain a "sanitized" stack trace, is now being passed in as the fifth parameter to onerror in Chrome. You can read about it here: https://code.google.com/p/chromium/issues/detail?id=147127

At the time of this writing it's in Canary and should be pushed out to the stable Chrome release sometime later this month. If you're running Canary you can test it like so:

window.onerror = function (message, file, line, column, errorObj) {
    if(errorObj !== undefined) //so it won't blow up in the rest of the browsers
        console.log('Error: ' + errorObj.stack);
}

You can see as per the spec that they've also added the column number which IE 10 has also implemented.

You can also checkout the Mozilla discussion: https://bugzilla.mozilla.org/show_bug.cgi?id=355430


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...