1 var apply = require('./_apply'),
2 baseRest = require('./_baseRest'),
3 isError = require('./isError');
6 * Attempts to invoke `func`, returning either the result or the caught error
7 * object. Any additional arguments are provided to `func` when it's invoked.
13 * @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.
18 * // Avoid throwing errors for invalid selectors.
19 * var elements = _.attempt(function(selector) {
20 * return document.querySelectorAll(selector);
23 * if (_.isError(elements)) {
27 var attempt = baseRest(function(func, args) {
29 return apply(func, undefined, args);
31 return isError(e) ? e : new Error(e);
35 module.exports = attempt;