Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Add an error handler for all event callbacks #542

wants to merge 1 commit into from

2 participants


Javascript has a default error handler window.onerror though there are several issues with this, the most poignant being that you can't get at the error object itself, nor the associated stack trace.

Due to the large amount of code that ends up being run as a direct consequence of user-interaction on a webpage, allowing developers to catch all errors that are raised within event handlers added by zepto allows significantly improved debugging ability (particularly when coupled to a service like Airbrake or Bugsnag).

Obviously this is no substitute for handling errors locally; but it does significantly help with tracking down hard to find problems and unexpected exceptions.

This patch was inspired by a similar change made to ember.js emberjs/ember.js@99125d9...539f5a1#L0R40 (MIT license).


I don't think this is an issue, exceptions are thrown and should pop up in the debugger of your browser, no? I'm unsure about the specific use case here. Feel free to reopen with specific examples.

@madrobby madrobby closed this

At work we used an exception tracker (there are a few,,, etc.) so that exceptions that happen in production can still be tracked.

Without a change like this, it's basically impossible to get enough information from a crash for an exception report to be useful. The installer you get if you visit on an iPhone is using this patch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 6, 2012
  1. @ConradIrwin
This page is out of date. Refresh to see the latest.
Showing with 8 additions and 1 deletion.
  1. +8 −1 src/event.js
9 src/event.js
@@ -41,7 +41,14 @@
var delegate = getDelegate && getDelegate(fn, event),
callback = delegate || fn
var proxyfn = function (event) {
- var result = callback.apply(element, [event].concat(
+ var result
+ if ($.onerror) {
+ try {
+ result = callback.apply(element, [event].concat(
+ } catch(e) { $.onerror(e) }
+ } else {
+ result = callback.apply(element, [event].concat(
+ }
if (result === false) event.preventDefault()
return result
Something went wrong with that request. Please try again.