1 var isError = require('../lang/isError'),
2 restParam = require('../function/restParam');
5 * Attempts to invoke `func`, returning either the result or the caught error
6 * object. Any additional arguments are provided to `func` when it's invoked.
11 * @param {Function} func The function to attempt.
12 * @returns {*} Returns the `func` result or error object.
15 * // avoid throwing errors for invalid selectors
16 * var elements = _.attempt(function(selector) {
17 * return document.querySelectorAll(selector);
20 * if (_.isError(elements)) {
24 var attempt = restParam(function(func, args) {
26 return func.apply(undefined, args);
28 return isError(e) ? e : new Error(e);
32 module.exports = attempt;