Saturday 20 January 2018

JavaDoc: @throws: specify the exception thrown by method

@throws tag is used to specify the exception thrown by a method (or) constructor.

Syntax
@throws class-name description

Can I use multiple throws tags to specify different exceptions?
Yes

Example
/**
 *
 * @throws IllegalArgumentException
 *             thrown if radius < 0.
 */
public double areaOfCircle(int radius) throws IllegalArgumentException;

Arithmetic.java
package com.java.tags;

/**
 * 
 * @author Hari Krishna
 * 
 * @since 1.0
 */
public interface Arithmetic {

 /**
  * The value of PI is {@value}
  */
 public static final double PI = 3.14;

 /**
  * 
  * @param radius
  *            radius of the circle
  * 
  * @return area of the circle
  * 
  * @throws IllegalArgumentException
  *             thrown if radius < 0.
  */
 public double areaOfCircle(int radius) throws IllegalArgumentException;

}

javadoc is generated like below.



Previous                                                 Next                                                 Home

No comments:

Post a Comment