Zoltán Haindrich
Zoltán Haindrich

Reputation: 1808

How to document javadoc exception cause for multiple methods

is there a way to specify the way an exception cause gets documented?

i have a class with a bunch of methods, which all throw nearly the same exceptions; example:

/**
 * some doc
 * @return value
 * @throws SpecificException when X happens
 */
public int fn1() throws SpecificException{
    return 0;
}

/**
 * some different doc
 * @return value
 * @throws SpecificException when X happens
 */
public int fn2() throws SpecificException{
    return 0;
}

i want to avoid copypasting the documentation for the @throws things.

is there a way to do this?

Upvotes: 2

Views: 1095

Answers (1)

Stephen C
Stephen C

Reputation: 718886

There is no way to do it using the standard javadoc tool and standard tags.

It is possible in theory to define custom javadoc tags and a custom Doclet class that propagates the common documentation comments across multiple methods. However, that makes your javadocs dependent on your customized javadoc setup. Furthermore, someone studying your APIs by looking at the source code is likely to miss that the comments for one method apply to others.

In short, its a bad idea. You are better off cut-and-pasting the relevant parts of the javadoc comments ... IMO.

Upvotes: 2

Related Questions