Если вы хотите рассматривать отмеченное исключение как непроверенное, вы можете сделать
До Java 7 вы можете сделать
} catch(SQLException e) {
Thread.currentThread().stop(e);
}
Однако в Java 8 вы можете сделать
/**
* Cast a CheckedException as an unchecked one.
*
* @param throwable to cast
* @param <T> the type of the Throwable
* @return this method will never return a Throwable instance, it will just throw it.
* @throws T the throwable as an unchecked throwable
*/
@SuppressWarnings("unchecked")
public static <T extends Throwable> RuntimeException rethrow(Throwable throwable) throws T {
throw (T) throwable; // rely on vacuous cast
}
и вызов
} catch(SQLException e) {
throw rethrow(e);
}
Проверенные исключения являются функцией компилятора и не обрабатываются по-разному во время выполнения.