The Javascript Error object contains different fields for different broswers:
in IE you have access to Error.name, Error.message, Error.number, and Error.description.
in FF you have access to Error.name, Error.message, Error.fileName, Error.lineNumber, and Error.stack (stack trace, shows "@" + Error.Filename + ":" + Error.lineNumber).
try {
// all your buggy code
} catch (e) {
// in FF you can add e.lineNumber or e.stack
alert("Error: " + e.name + " - " + e.message);
}
you can use this in IE, but unfortunately you can't trace it to the line number. For narrowing down the offending code in IE, add several "markers" in your code:
var myObject = new Object();
myObject.prototype.myFunction = function() {
alert('start');
// some code here
alert('1');
// some more code here
alert('2');
// some more code here
alert('3');
// some more code here
alert('done');
}
as your script loads, watch for the "Done with errors" icon as you dismiss the alerts. You can then narrow down where in your code the error is being thrown (i.e. "The error is thrown after '2' but before '3'..."). This is definitely a tedious process, but it's tried and true, and more importantly will leave your code bug-free.