Comments on: Catching All JavaScript Errors in All Browsers http://mattsnider.com/architecture/catching-all-javascript-errors-in-all-browsers/ Understanding JavaScript and Frameworks Sun, 07 Sep 2008 03:56:34 +0000 http://wordpress.org/?v=2.1.2 By: Paul Irish http://mattsnider.com/architecture/catching-all-javascript-errors-in-all-browsers/#comment-10179 Paul Irish Sun, 06 Apr 2008 17:54:47 +0000 http://mattsnider.com/architecture/catching-all-javascript-errors-in-all-browsers/#comment-10179 Smart work, as always. When using technique, however, keep in mind that there is a <a href="http://www.rockstarapps.com/wordpress/?p=76" rel="nofollow">performance hit to the use of try/catch</a>. Smart work, as always. When using technique, however, keep in mind that there is a performance hit to the use of try/catch.

]]>
By: Matt Snider http://mattsnider.com/architecture/catching-all-javascript-errors-in-all-browsers/#comment-10180 Matt Snider Sun, 06 Apr 2008 18:11:10 +0000 http://mattsnider.com/architecture/catching-all-javascript-errors-in-all-browsers/#comment-10180 Paul, Great work, I have experienced the performance that you describe, but never quantified it. Thanks for the effort. Paul,

Great work, I have experienced the performance that you describe, but never quantified it. Thanks for the effort.

]]>
By: Ryan Dunphey http://mattsnider.com/architecture/catching-all-javascript-errors-in-all-browsers/#comment-10211 Ryan Dunphey Mon, 07 Apr 2008 05:52:21 +0000 http://mattsnider.com/architecture/catching-all-javascript-errors-in-all-browsers/#comment-10211 We considered doing something similar which involved hacking yui's addlistener, but decided against it for the following reasons: 1.) we have a decent qa on staff (finally!) 2.) most errors will be caught by IE/FF 3.) it felt too so darn dirty 4.) performance ...in that order. We considered doing something similar which involved hacking yui’s addlistener, but decided against it for the following reasons:

1.) we have a decent qa on staff (finally!)
2.) most errors will be caught by IE/FF
3.) it felt too so darn dirty
4.) performance

…in that order.

]]>
By: MillsJROSS http://mattsnider.com/architecture/catching-all-javascript-errors-in-all-browsers/#comment-10228 MillsJROSS Mon, 07 Apr 2008 12:37:14 +0000 http://mattsnider.com/architecture/catching-all-javascript-errors-in-all-browsers/#comment-10228 I don't think there's a clean way to do proper error checking in JavaScript. I've always found the try/catch syntax to be awkward for most cases. However, to create a method that tracks all errors, using try/catch is unavoidable. I think the method you provided is a bit heavy handed. I think it would be better to just have a central method with one try/catch that runs all the other functions when an event is triggered. If it errors you don’t have as much insight as to what happened, but you can use your event object to find out what the source object was, what event triggered it, the browser the user was working from, etc…Then you try to narrow down what went wrong. You don’t have to worry about the performance hit as you’re only calling the one try/catch. I don’t think there’s a clean way to do proper error checking in JavaScript. I’ve always found the try/catch syntax to be awkward for most cases. However, to create a method that tracks all errors, using try/catch is unavoidable. I think the method you provided is a bit heavy handed. I think it would be better to just have a central method with one try/catch that runs all the other functions when an event is triggered. If it errors you don’t have as much insight as to what happened, but you can use your event object to find out what the source object was, what event triggered it, the browser the user was working from, etc…Then you try to narrow down what went wrong. You don’t have to worry about the performance hit as you’re only calling the one try/catch.

]]>
By: Lowell http://mattsnider.com/architecture/catching-all-javascript-errors-in-all-browsers/#comment-19775 Lowell Wed, 30 Jul 2008 05:42:43 +0000 http://mattsnider.com/architecture/catching-all-javascript-errors-in-all-browsers/#comment-19775 I have a couple of ideas: 1) put the object first, and method name second in call_user_method_array(). That way they are in the same order as a function call. 2) if not, you could make the 2nd argument default to window if it is not supplied, to keep the calling code simpler. 3) rather than pass an array as the third param, you could get the values from the arguments array. It would look something like this: var call_user_method_array = function(method_name, obj /*, paramarr*/) { var args = Array.prototype.slice.call(arguments, 2); try { return (obj||window)[method_name].apply((obj||window), args); } catch (e) { window.onerror(e.message, window.location, ‘-1′); // use -1 for exceptions return null; } } I have a couple of ideas:

1) put the object first, and method name second in call_user_method_array(). That way they are in the same order as a function call.

2) if not, you could make the 2nd argument default to window if it is not supplied, to keep the calling code simpler.

3) rather than pass an array as the third param, you could get the values from the arguments array. It would look something like this:

var call_user_method_array = function(method_name, obj /*, paramarr*/) {
var args = Array.prototype.slice.call(arguments, 2);
try {
return (obj||window)[method_name].apply((obj||window), args);
}
catch (e) {
window.onerror(e.message, window.location, ‘-1′); // use -1 for exceptions
return null;
}
}

]]>
By: Matt Snider http://mattsnider.com/architecture/catching-all-javascript-errors-in-all-browsers/#comment-19820 Matt Snider Wed, 30 Jul 2008 16:32:41 +0000 http://mattsnider.com/architecture/catching-all-javascript-errors-in-all-browsers/#comment-19820 Good points... thanks for you thoughts, Lowell. Good points… thanks for you thoughts, Lowell.

]]>