Improving JavaScript Error Reporting

So now we have a common code to report errors either from our code or from third-party code. Our project is the JQM / Phonegap project for iOS. What happens, we almost always get the same useless error ... TypeError: 'undefined' is not a function ... without a line number or other useful information. Is there a way to change the code, maybe get WHAT undefined or WHERE?

window.onerror = function myErrorHandler(errorMsg, url, lineNumber) { //Handle errors not in a jquery event handler //DebugMessage(errorMSg + " "+ url + " " + lineNumber); var ex = new Error(errorMsg, url, lineNumber); HandleError(ex, "window.onerror"); //HandleError sends the error object to //a webservice to log the error. return true; }; 

Any tips for debugging javascript errors will also help.

+8
javascript jquery-mobile ios error-handling cordova
source share
2 answers

In recent months, browsers have expanded the window.onerror signature to provide additional information.

 window.onerror = function(msg, file, line, col, error) { // backwards compat if (!error) { error = new Error(msg); } // send error to your logger } 

This will give you much more information. But there are still things where you need a better context. You should check out some third-party tools for this, such as TrackJS , which automatically give you this, as well as additional information on how the error occurred.

Disclaimer: I am one of the original authors of TrackJS, so I know a bunch of JavaScript errors :)

+1
source share

Have you heard of Ripple ? This is a mobile emulator for Chrome designed to test PhoneGap applications.

This can help you find your errors before debugging on devices.

0
source share

All Articles