The situation is quite simple: if your exception does not have business value, that is, it is just a failure, of course, use the exception without checking. If you need to handle the exception in a way specific to this exception, which in most cases means that the processing code will include business logic, then it is still OK to use the excluded exception , but there are at least some advantages when using the checked exception. However, in any case, the unhandled exception that you get from the JSON API is useless, and this is just a sign of poor public API design.
As a side note, I came across this beautifully stupid piece of code (author: Lukas Eder) that will allow you to throw your original excluded exception without packaging!
public static <R> R trhow(Throwable t) { return UncheckedThrower.<RuntimeException, R>trhow0(t); } @SuppressWarnings("unchecked") private static <E extends Exception, R> R trhow0(Throwable t) throws E { throw (E)t; }
Of course, these are powerful things that should only be consumed by adult Compromisers.
source share