Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In javadoc, what is the difference between the tags @throws and @exception?

Tags:

java

javadoc

Take the following implementation of a array-based stack of chars for example:

public char peek() throws Underflow {     if (!isEmpty()) {         return stack[pos];     } else {         throw new Underflow("Peeking at an empty stack.");     } } 

Back when I'm using just a text editor I always use the @exception tag, but now my IDE (Netbeans) used @throws when generating the javadoc.

So my question is, what is the difference between the two and when should one be preferred over another (using the above code for example)?

like image 876
jon2512chua Avatar asked Apr 01 '11 07:04

jon2512chua


People also ask

What are Javadoc tags?

The javadoc TagsRepresents the relative path to the generated document's root directory from any generated page. Adds a comment indicating that this API should no longer be used. Adds a Throws subheading to the generated documentation, with the classname and description text.

What is Javadoc style?

Javadoc (originally cased JavaDoc) is a documentation generator created by Sun Microsystems for the Java language (now owned by Oracle Corporation) for generating API documentation in HTML format from Java source code.

How do you write a good Javadoc comment?

Use the standard style for the Javadoc comment Javadoc only requires a '/**' at the start and a '*/' at the end. In addition to this, use a single star on each additional line: /** * Standard comment. */ public ... /** Compressed comment.

What is throws in Java with example?

The throws keyword indicates what exception type may be thrown by a method. There are many exception types available in Java: ArithmeticException , ClassNotFoundException , ArrayIndexOutOfBoundsException , SecurityException , etc. Syntax: throw is followed by an object (new type)


1 Answers

There is none, they're synonyms. From the docs:

Documenting Exceptions with @throws Tag
NOTE - The tags @throws and @exception are synonyms.

like image 66
T.J. Crowder Avatar answered Sep 22 '22 19:09

T.J. Crowder