Atitit.js Global exception capture in a browser environment

Source: Internet
Author: User
Tags stack trace

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.