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?
@throws SomeException enumerating many conditions, is noise, can be misunderstood as only one condition, and certainly makes the last conditions easy to miss
, but having@throws SameException listed once
and@throws SameException twice
brings attention to unique conditions. I ended my first sentence with a question mark because I am like many others biased by our culture and habits. – Delwin