(no title)
rogerkeays | 2 years ago
public static RuntimeException unchecked(Exception e) {
Exceptions.<RuntimeException>throw_checked(e);
return null;
}
private static <E extends Exception> void throw_checked(Exception e) throws E {
throw (E) e;
}
then you can do this: try { ...
} catch (IOException e) {
throw unchecked(e);
}
And the original exception is thrown without being wrapped. It's as though you had `throws IOException` on your method signature.This is from my original solution to the problem: https://github.com/rogerkeays/jamaica-core/blob/0cc98b114998...
vbezhenar|2 years ago
So yes, you can throw IOException masking it to RuntimeException, however you can't catch it later without another gimmicks like catching Exception and checking if it's IOException (and even that check causes linter warnings in Idea, so now you need to suppress those warnings...).
Throwing and catching UncheckedIOException does not have this problem.
rogerkeays|2 years ago