/** * lodash 3.1.0 (Custom Build) * Build: `lodash modern modularize exports="npm" -o ./` * Copyright 2012-2015 The Dojo Foundation * Based on Underscore.js 1.7.0 * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors * Available under MIT license */ var baseSlice = require('lodash._baseslice'), isError = require('lodash.iserror'); /** * Attempts to invoke `func`, returning either the result or the caught error * object. Any additional arguments are provided to `func` when it is invoked. * * @static * @memberOf _ * @category Utility * @param {*} func The function to attempt. * @returns {*} Returns the `func` result or error object. * @example * * // avoid throwing errors for invalid selectors * var elements = _.attempt(function(selector) { * return document.querySelectorAll(selector); * }, '>_>'); * * if (_.isError(elements)) { * elements = []; * } */ function attempt(func) { try { return func.apply(undefined, baseSlice(arguments, 1)); } catch(e) { return isError(e) ? e : new Error(e); } } module.exports = attempt;