Created
July 22, 2011 20:55
-
-
Save bobpoekert/1100404 to your computer and use it in GitHub Desktop.
Catch array of exceptions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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