Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javadoc and RuntimeException

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("");
}

2 Answers

If you use the JDK as a guidance, RuntimeException are not in the methods signature but are documented in the javadoc. You can have a look at collections for example.

like image 123
assylias Avatar answered Sep 08 '25 10:09

assylias


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("");
}
like image 43
Priyank Doshi Avatar answered Sep 08 '25 10:09

Priyank Doshi