Skip to content

Instantly share code, notes, and snippets.

@calvinmetcalf
Created October 5, 2013 00:34
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 calvinmetcalf/6835039 to your computer and use it in GitHub Desktop.
Save calvinmetcalf/6835039 to your computer and use it in GitHub Desktop.
function handleError(func){
return new Proxy(func,{
apply:function(origionalFunction,scope,arguments){
var result;
try{
result = origionalFunction.apply(scope,arguments);
}catch(e){
result = e;
}finally{
return result;
}
}
});
}
function crafty(a){
if(typeof a === 'string'){
throw 'we cant have '+a;
}else{
return a + a;
}
}
var notSoCrafty = handleError(crafty);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment