If a method can throw several exceptions, how to declare it?

I think Throws Exception handles the general case. If my method will throw a specific exception, how to declare it?

+6
java
source share
3 answers
public writeThisToFile(String line) throws FileNotFoundException, AppSpecificServiceException, SecurityException{ /* some thing */ } 

see also

+13
source share
 public void yourMethod() throws anException, anotherException { //stuff here } 
+6
source share

Using the throws :

 public void myMethod() throws Exception1, Exception2 { ... } 
+4
source share

All Articles