官方推荐 /编码样式指南有关在Javadoc中使用多个@Throws标签的同一例外的指南

发布于 2025-02-07 09:19:00 字数 690 浏览 3 评论 0原文

我最近发现在Javadoc中使用多个@throws标签中的同一例外。

“ https://en.wikipedia.org/wiki/connect_four”中记录了他的一种方法

/*
 * ...
 * @throws IllegalArgumentException if the number of rows or columns is invalid 
 * @throws IllegalArgumentException if one of the players has {@link Stone#None} as stone
 * @throws IllegalStateException if both players use the same stone color
 */
public void doSomething(...) { ... }

我的一位学生用它在 @throws 标签的官方样式指南或一般建议,或者使用多个异常类型使用多个类型?

I just recently found out that one can use multiple @throws tags for the same exception in Javadoc.

One of my students used it to document one of his methods in Connect Four:

/*
 * ...
 * @throws IllegalArgumentException if the number of rows or columns is invalid 
 * @throws IllegalArgumentException if one of the players has {@link Stone#None} as stone
 * @throws IllegalStateException if both players use the same stone color
 */
public void doSomething(...) { ... }

Now my (and his) question: Is there an official style guide or a general recommendation on whether to use a single @throws tag or "is it fine" to use multiple ones per exception type?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

长梦不多时 2025-02-14 09:19:00

有针对Javadocs的Oracle样式指南:

这是否算作“官方”取决于您的观点。无论哪种方式,对于同一例外,我都看不到该文档中的多个标签的任何提及。

但是,根据以下Q& a,由标准Javadoc工具链支持 支持的 支持支持 ;即它们每个都将导致生成的HTML进入。

(我的个人意见是Javadocs会更多如果您不这样做,可以阅读,但这只是我的意见。)

There is an Oracle style guide for javadocs:

Whether that counts as "official" depends on your point of view. Either way, I cannot see any mention in that document of multiple tags for the same exception.

However, according to the following Q&A, multiple @throws tags for the same exception is supported by the standard Javadoc tool chain; i.e. each of them will result in an entry in the generated HTML.

(My personal opinion is the javadocs will be more readable if you don't do this, but that is just my opinion.)

七禾 2025-02-14 09:19:00

我不确定这是否回答了您的问题,但是这篇文章 (恰好有一个带有多个@throws的示例,尽管不是本文的主题)建议您根本不应该记录这些例外文档只会重复@param标签的条件。

I'm not sure if this answers your question, but this article (which happens to have an example with multiple @throws with the same exception, although it's not the topic of the article) suggests you shouldn't be documenting those exceptions at all, because they are unchecked and the documention would only repeat conditions of the @param tags.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文