Consider the Java code snippet below:
public <T> T create(Class<T> clazz) throws InstantiationException, IllegalAccessException {
return clazz.newInstance();
}
This in Eclipse (Neon.2, JDK 8) with SonarLint performing static code analysis. It is providing a recommendation to refactor this:
Refactor this method to throw at most one checked exception instead of: java.lang.InstantiationException, java.lang.IllegalAccessException
What best practice is the basis for this recommendation? I understand there's some controversy about checked exceptions in general, but why would it be better in this instance to catch one here and pass the other up the stack vs. passing them both up the stack for something else to handle them?