简体   繁体   English

关于在 JavaDoc 中对同一异常使用多个 @throws 标签的官方推荐/编码风格指南

[英]Official recommendation / coding style guide on using multiple @throws tags for the same exception in JavaDoc

I just recently found out that one can use multiple @throws tags for the same exception in Javadoc .我最近才发现可以在 Javadoc 中为同一个异常使用多个@throws标签

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?现在我的(和他的)问题:是否有官方风格指南或一般建议是否使用单个@throws标签或“是否可以”为每种异常类型使用多个标签?

There is an Oracle style guide for javadocs: javadocs 有一个 Oracle 风格指南:

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;但是,根据以下问答,标准 Javadoc 工具链支持同一异常的多个@throws标签; ie each of them will result in an entry in the generated HTML.即,它们中的每一个都会在生成的 HTML 中产生一个条目。

(My personal opinion is the javadocs will be more readable if you don't do this, but that is just my opinion .) (我个人的看法是,如果你不这样做,javadocs 会更具可读性,但这只是我的看法。)

我不确定这是否能回答您的问题,但这篇文章(恰好有一个带有多个@throws的示例,但具有相同的异常,尽管这不是文章的主题)建议您根本不应该记录这些异常,因为它们未选中,并且文档只会重复@param标记的条件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM