summaryrefslogtreecommitdiff
path: root/tools/eslint/node_modules/js-yaml/node_modules/argparse/node_modules/lodash/utility/attempt.js
diff options
context:
space:
mode:
Diffstat (limited to 'tools/eslint/node_modules/js-yaml/node_modules/argparse/node_modules/lodash/utility/attempt.js')
-rw-r--r--tools/eslint/node_modules/js-yaml/node_modules/argparse/node_modules/lodash/utility/attempt.js32
1 files changed, 32 insertions, 0 deletions
diff --git a/tools/eslint/node_modules/js-yaml/node_modules/argparse/node_modules/lodash/utility/attempt.js b/tools/eslint/node_modules/js-yaml/node_modules/argparse/node_modules/lodash/utility/attempt.js
new file mode 100644
index 0000000000..80afe6924c
--- /dev/null
+++ b/tools/eslint/node_modules/js-yaml/node_modules/argparse/node_modules/lodash/utility/attempt.js
@@ -0,0 +1,32 @@
+var isError = require('../lang/isError'),
+ restParam = require('../function/restParam');
+
+/**
+ * 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 {Function} 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 = [];
+ * }
+ */
+var attempt = restParam(function(func, args) {
+ try {
+ return func.apply(undefined, args);
+ } catch(e) {
+ return isError(e) ? e : new Error(e);
+ }
+});
+
+module.exports = attempt;