1 var apply = require('./_apply'),
2 isObject = require('./isObject'),
3 rest = require('./rest');
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.
12 * @param {Function} func The function to attempt.
13 * @returns {*} Returns the `func` result or error object.
16 * // Avoid throwing errors for invalid selectors.
17 * var elements = _.attempt(function(selector) {
18 * return document.querySelectorAll(selector);
21 * if (_.isError(elements)) {
25 var attempt = rest(function(func, args) {
27 return apply(func, undefined, args);
29 return isObject(e) ? e : new Error(e);
33 module.exports = attempt;