I have a java method which is potent of throwing multiple unchecked exceptions. My question is: do I need to declare it to throw all the the exceptions or Is there any problem if I declare throws Exception only?
Method 1:
public void myMethod() throws Exception1,Exception2,Exception3,Exception4,Exception5
{}
Instead of method 1, can I declare like this?
public void myMethod() throws Exception
{}
解决方案
Yes, you can define. But, method caller will loose some information about the exception thrown. Best practise is to throw specific exception and handle them specifically.