官方推荐 /编码样式指南有关在Javadoc中使用多个@Throws标签的同一例外的指南
我最近发现在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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有针对Javadocs的Oracle样式指南:
这是否算作“官方”取决于您的观点。无论哪种方式,对于同一例外,我都看不到该文档中的多个标签的任何提及。
但是,根据以下Q& a,由标准Javadoc工具链支持 支持的 支持支持 ;即它们每个都将导致生成的HTML进入。
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.)
我不确定这是否回答了您的问题,但是这篇文章 (恰好有一个带有多个
@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.