- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface public interface ExceptionPropagator<K,V> extends DataAwareCustomization<K,V>In read through mode exceptions are cached. Every time an entry is requested from the cache a new exception is generated that wraps the original loader exception in a
CacheLoaderException. This behavior can be modified by registering a custom exception propagator.
Exceptions should not be thrown directly but wrapped. Using this customization it is possible to change the exception type or the message according to the information available.
The propagator is only used when a value is accessed. It is not used when a cache operation is triggered explicitly which might cause an exception, e.g.
Rationale: Although exceptions are propagated at many places, this happens for each exception once. This class addresses the situation where a single exception is possibly rethrown many times. More customization might be wanted, and, it would be very cumbersome to wrap any value access of the cache API in a
try ... catch.
- Jens Wilke
RuntimeException propagateException(LoadExceptionInfo<K,V> loadExceptionInfo)Called when an entry value with exception is accessed. Potentially wraps and rethrows the original exception.
The default implementation wraps the exception into a
CacheLoaderExceptionand contains some id or timestamp of the original exception to show that we might through multiple exceptions on each entry access for a single loader exception.
API rationale: We create an exception instead of doing a
throwin the exception propagator, to keep the control flow obvious in the calling method.
loadExceptionInfo- information of original exception and when the original exception occurred.