Attempts to invoke func, returning either the result or the caught error object. Any additional arguments are provided to func when it's invoked.
func
5.3.0
// Avoid throwing errors for invalid selectors.const elements = attempt(selector => document.querySelectorAll(selector), '>_>')if (isError(elements)) { elements = []} Copy
// Avoid throwing errors for invalid selectors.const elements = attempt(selector => document.querySelectorAll(selector), '>_>')if (isError(elements)) { elements = []}
The function to attempt.
Rest
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 tofunc
when it's invoked.Since
5.3.0
Example