Atitit.js Global exception capture in a browser environment
Window.onerror = function (errormessage, Scripturi, linenumber) {
var s= json.stringify (arguments); alert (s);
Alert (errormessage
Message:errormessage,
Script:scripturi,
Line:linenumber
}
Different browsers have different implementations of onerror, and different parameters are defined for phones and PCs . The number of parameters. So it 's better to use json .
Window.onerror
for Try-catch not covered, if an exception occurs, you can only pass Window.onerror to capture it.
Window.onerror =
function (errormessage, Scripturi, linenumber) {
ReportError ({
Message:errormessage,
Script:scripturi,
Line:linenumber
});
}
Be careful not to be clever with Window.addeventlistener or window.attachevent the form to monitor Window.onerror . Many browsers only implement the Window.onerror , or is only Window.onerror the implementation is standard. Considering that the definition of the draft standard is also Window.onerror , we use Window.onerror just fine.
property is missing
Suppose we have a ReportError function is used to collect caught exceptions and then send them to server-side storage for query analysis, what information do we want to collect? More useful information includes: Error type ( name), error message (message), the script file address (Script), line number ( Line), column number (column), stack trace (Stack ). If an exception is passed Try-catch captured, this information is Error Object (supported by the mainstream browser), so ReportError This information can also be collected. But if it is through Window.onerror captured, we all know that this event function has only 3 parameters, so the unexpected information of these 3 parameters is lost.
JS Advanced Debugging Tips: Capture and analyze JavaScript error Details _javascript tips _ Scripting House. htm
JS Advanced Debugging Tips: Capturing and parsing JavaScript Error details _javascript Tips _ Scripting House . htm
JSON object and json string Transfer (4 conversions ) _json_ Script House . htm
author:: Nickname :Old Wow's claws( Full Name::AttilaxAkbar Al Rapanui Attilaksachanui)
Kanji Name: Etila ( Ayron) , email:[email protected]
reprint Please indicate source: http://www.cnblogs.com/attilax/
Atiend
Atitit.js Global exception capture in a browser environment