Skip to content

Instantly share code, notes, and snippets.

@ih2502mk
Created June 3, 2014 21:24
Show Gist options
  • Save ih2502mk/eb06da4cbf87e708d5e2 to your computer and use it in GitHub Desktop.
Save ih2502mk/eb06da4cbf87e708d5e2 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
</body>
</html>
////--------
function decor(fn, errorHandler) {
return function() {
try {
return fn.apply(null, arguments);
}
catch(e) {
errorHandler(e);
}
};
}
////--------
function a(b, c) {
if (b > 6) {
throw new Error("aaaaa");
}
return b + c;
}
var decorated_a = decor(a, function(e){
console.log("Handled elsewhere!");
});
console.log(decorated_a(1, 4));
console.log(decorated_a(7, 4));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment