When would a situation call for a method to have both throws
and throw
when the calling method will catch the throws
anyway. Take the following method with a custom exception created for my personal program for example.
.....
.....
public String get() throws EmptyQueueException {
if( planet == mars)
throw new EmptyQueueException();
return galaxy;
.....
.....
Sure one declares and one actually pass on the exception but this method is not responsible. I mean if you know this particular exception is going to happen why write it twice considering either will be caught by the invoking method that would have caught it anyway. Why write both throw and throws when one is enough ?