当前位置: 首页 > 文档资料 > JSDoc 中文文档 >

@throws

优质
小牛编辑
126浏览
2023-12-01

描述: 说明可能会被抛出什么样的错误。

别名:

  • exception

语法

  • @throws free-form description
  • @throws {<type>}
  • @throws {<type>} free-form description

Overview

@throws标签可以让你描述函数可能会抛出的错误。在一个JSDoc注释块中您可以包含多个@throws标签。

例子

例如,在type中使用@throws标签:

/**
 * @throws {InvalidArgumentException}
 */
 function foo(x) {}

例如,在描述中使用@throws标签:

/**
 * @throws Will throw an error if the argument is null.
 */
 function bar(x) {}

例如,在type和描述中使用@throws标签:

/**
 * @throws {DivideByZero} Argument x must be non-zero.
 */
 function baz(x) {}