If you want to treat a checked exception as an unchecked one, you can do
Up to Java 7 you can do
} catch(SQLException e) {
Thread.currentThread().stop(e);
}
However in Java 8 you can do
/**
* 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
}
and call
} catch(SQLException e) {
throw rethrow(e);
}
Checked exceptions are a compiler feature and are not treated differently at runtime.