JavadocNoErrorInThrowsTag

Since Checkstyle 14.1.0

Description

Checks that Error types are not documented in @throws or @exception Javadoc tags.

Per the documentation comments style guide, errors generally should not be documented because they are unpredictable. This check reports documented throwable names whose simple name ends with Error, unless the same Error type is explicitly thrown with throw new in the documented method or constructor.

Properties

name description type default value since
violateExecutionOnNonTightHtml Control when to print violations if the Javadoc being examined by this check violates the tight html rules defined at Tight-HTML Rules. boolean false 14.1.0

Examples

To configure the check:


<module name="Checker">
  <module name="TreeWalker">
    <module name="JavadocNoErrorInThrowsTag"/>
  </module>
</module>

Example1:


class Example1 {
  /**
   * Valid Javadoc.
   *
   * @throws IOException if an input or output exception occurs.
   * @throws IllegalArgumentException if the argument is invalid.
   */
  void validExceptions() throws IOException {
  }

  /**
   * Valid explicit Error.
   *
   * @throws OutOfMemoryError if memory is exhausted.
   */
  void validExplicitError() {
    throw new OutOfMemoryError("memory exhausted");
  }

  // violation 5 lines below """Error type 'StackOverflowError' should not be
  // documented in '@throws' tag."""
  /**
   * Invalid Javadoc.
   *
   * @throws StackOverflowError if recursion is too deep.
   */
  void invalidError() {
  }
}

Example of Usage

Violation Messages

All messages can be customized if the default message doesn't suit you. Please see the documentation to learn how to.

Fully Qualified Name

com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocNoErrorInThrowsTagCheck

Use this fully qualified class name in configuration when an exact class reference is required.

Parent Module

TreeWalker