I am curious about if I should add throws ExceptionClass or not after the method's signature.(ExceptionClass extends RuntimeException)
For instance:
public void foo() // throws ExceptionClass
{
// ...
throw new ExceptionClass("");
}
解决方案
Ideally you don't need to add runtime exception in method's throws clause. Since you want the consumer of this method to be aware of chances that this method may throw exception , i would say use javadoc either. Below is example of how you should use :
/**
*
* @throws ExceptionClass
*/
public void foo()
{
// ...
throw new ExceptionClass("");
}