I was going through the java source code for LocalDate API, and found that the methods are missing throws declaration. However the javadoc clearly mentions that the method could throws DateTimeException. Below is the source from LocalDate API from Java 8 .
/**
* Formats this date using the specified formatter.
* <p>
* This date will be passed to the formatter to produce a string.
*
* @param formatter the formatter to use, not null
* @return the formatted date string, not null
* @throws DateTimeException if an error occurs during printing
*/
@Override // override for Javadoc and performance
public String format(DateTimeFormatter formatter) {
Objects.requireNonNull(formatter, "formatter");
return formatter.format(this);
}
- Should this be the right way to declare a method which throws exception (I expected throws in method signature which enables the clients to properly handle the exception, but this does not give the client a clue about exception unless the javadoc is being read) ?
Please me know if I missed something to understand this properly?