开发者

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

开发者 https://www.devze.com 2023-02-16 22:52 出处:网络
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,

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
{
    ...
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号