Search code examples
javajavadoc

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


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)?


Solution

  • There is none, they're synonyms.

    From the docs:

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