I have a cache implementation where in as a part of the Callable implementation (i.e. call method) I raise a Checked exception (sub-classsed from Exception). See the code snippet below. Is this is the right way of throwing a custom exception from the cache loading process ? Rest of my code is strongly dependent on the CustomCheckedException handling so I want to make sure that the approach below is the right way to go !! The method doSomething throws the CustomCheckedException.
public class ABiggerClass {
...
private SomeClass getSomeData(ParamClass param) throws CustomCheckedException {
SomeClass d = null;
try {
d = someCache.get(getCacheKey(),
new CacheLoader(param));
} catch (ExecutionException e) {
e.printStackTrace();
Throwables.propagateIfInstanceOf(e.getCause(),
CustomCheckedException.class);
}
return d;
}
private class CacheLoader implements Callable<SomeClass> {
private ParamClass param;
@Override
public SomeClass call() throws Exception {
SomeClass result = new SomeClass();
result.doSomething(param);
return result;
}
public CacheLoader(ParamClass param) {
super();
this.param = param;
}
}
...
}