If a method can throw multiple exceptions, how to declare it?
I think throws Exception
only handles the general case.
If my method 开发者_运维问答can throw multiple exceptions, how to declare it?
public writeThisToFile(String line) throws FileNotFoundException, AppSpecificServiceException, SecurityException{
/* some thing */
}
See Also
- § 8.4.6 Method Throws
public void yourMethod() throws anException, anotherException {
//stuff here
}
Using the throws
clause:
public void myMethod()
throws Exception1, Exception2
{
...
}
精彩评论