Skip to content

Instantly share code, notes, and snippets.

@bobpoekert
Created July 22, 2011 20:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bobpoekert/1100404 to your computer and use it in GitHub Desktop.
Save bobpoekert/1100404 to your computer and use it in GitHub Desktop.
Catch array of exceptions
var catcher = function() {
var fns = Array.prototype.slice.call(arguments);
var onerror = fns[0];
fns.splice(0, 1);
return function() {
var res = [];
var errors = [];
for (var i=0; i < fns.length; i++) {
try {
res.push(fns[i].apply(this, arguments));
} catch (e) {
errors.push(e);
res.push(null);
}
}
if (errors.length > 0) {
onerror(errors);
}
return res;
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment