CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes45downloads
attempt.js36 linesDownload Raw Back to lodash
1var apply = require('./_apply'),2    baseRest = require('./_baseRest'),3    isError = require('./isError');4 5/**6 * Attempts to invoke `func`, returning either the result or the caught error7 * object. Any additional arguments are provided to `func` when it's invoked.8 *9 * @static10 * @memberOf _11 * @since 3.0.012 * @category Util13 * @param {Function} func The function to attempt.14 * @param {...*} [args] The arguments to invoke `func` with.15 * @returns {*} Returns the `func` result or error object.16 * @example17 *18 * // Avoid throwing errors for invalid selectors.19 * var elements = _.attempt(function(selector) {20 *   return document.querySelectorAll(selector);21 * }, '>_>');22 *23 * if (_.isError(elements)) {24 *   elements = [];25 * }26 */27var attempt = baseRest(function(func, args) {28  try {29    return apply(func, undefined, args);30  } catch (e) {31    return isError(e) ? e : new Error(e);32  }33});34 35module.exports = attempt;36 
basant307/AI_Governance_Project · CoolFace