企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
## attempt + [link](./attempt "Link to this entry.") + [source](https://github.com/lodash/lodash/blob/4.5.0正式版/lodash.src.js#L13095 "View in source.") + [npm](https://www.npmjs.com/package/lodash.attempt "See the npm package.") ``` _.attempt(func) ``` 尝试调用函数,返回结果 或者 错误对象。 任何附加的参数都会在调用时传给函数。 ### 参数 1. func (Function) 要调用的函数 ### 返回值 (\*) 返回函数结果或者错误对象 ### 示例 ``` // 避免因为错误的选择器而抛出 var elements = _.attempt(function(selector) { return document.querySelectorAll(selector); }, '>_>'); if (_.isError(elements)) { elements = []; } ```