COLLECTED BY
Organization:
Internet Archive
Focused crawls are collections of frequently-updated webcrawl data from narrow (as opposed to broad or wide) web crawls, often focused on a single domain or subdomain.
The Wayback Machine - https://web.archive.org/web/20201220220134/https://github.com/lodash/lodash/blob/master/attempt.js
Permalink
Cannot retrieve contributors at this time
30 lines (28 sloc)
772 Bytes
import isError from './isError.js'
/**
* Attempts to invoke `func`, returning either the result or the caught error
* object. Any additional arguments are provided to `func` when it's invoked.
*
* @since 3.0.0
* @category Util
* @param {Function } func The function to attempt.
* @param {...* } [args] The arguments to invoke `func` with.
* @returns {* } Returns the `func` result or error object.
* @example
*
* // Avoid throwing errors for invalid selectors.
* const elements = attempt(selector =>
* document.querySelectorAll(selector), '>_>')
*
* if (isError(elements)) {
* elements = []
* }
*/
function attempt ( func , ...args ) {
try {
return func ( ...args )
} catch ( e ) {
return isError ( e ) ? e : new Error ( e )
}
}
export default attempt
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session.
You signed out in another tab or window. Reload to refresh your session.