Given that I basically want to eliminate checked exception usage and transform them to runtime exceptions, I would normally be doing something like this:
try {
As of Java 8 there's another way:
try {
// some code that can throw both checked and runtime exception
} catch (Exception e) {
throw rethrow(e);
}
@SuppressWarnings("unchecked")
public static RuntimeException rethrow(Throwable throwable) throws T {
throw (T) throwable; // rely on vacuous cast
}
* More info here.