attempt

Util
since 3.0.0

Arguments

  • Function The function to attempt.
  • ...* The arguments to invoke `func` with.

Returns

* the `func` result or error object.

Attempts to invoke func, returning either the result or the caught error object. Any additional arguments are provided to func when it's invoked.

Example of Lodash _.attempt

// Avoid throwing errors for invalid selectors.
var elements = _.attempt(function(selector) {
  return document.querySelectorAll(selector);
}, '>_>');

if (_.isError(elements)) {
  elements = [];
}