Wrap function that takes the execute function

                Never    
function wrap(execute) {
  return function () {
    try {
      return execute && execute();
    } catch (error) {
      execute = null;
      return null;
    }
  }
}

var errorExec = wrap(function () {
  throw new Error('Error');
});
var resultExec = wrap(function () {
  return "Result";
});
console.log(errorExec && errorExec()); // Should output null
console.log(errorExec && resultExec()); // Should output "Result"

Raw Text