You can always throw an UncheckedException
from a method, which need not be declared in the throws
clause.
So, you wrap your exception in any unchecked exception like that extends RuntimeException
or even RuntimeException
itself.
try {
//my logic
} catch(Exception e) {
throw new RuntimeException(e);
}
And just for the sake of completeness, it is a bad idea to have a single catch
block for Exception
, which will catch all the exceptions. Rather you should have catch
block for specific type of exception your method may throw.