JavaScript Exception Handling

Solution 1:

If you use a library like jQuery for assigning all your event handlers, you can use a combination of window.onerror and wrapping the jQuery event handler code and on ready function with an error handling function (see: JavaScript Error Tracking: Why window.onerror Is Not Enough).

  • window.onerror: catches all errors in IE (and most errors in Firefox), but does nothing in Safari and Opera.
  • jQuery event handlers: catches jQuery event errors in all browsers.
  • jQuery ready function: catches initialisation errors in all browsers.

Solution 2:

WebKit (Safari, Chrome, etc) now appears to support onerror.

Original post: As far as I know, WebKit/Safari does not support the onerror event. Which is a damn shame.