com.zeroleak.throwingsupplier.ThrowingSupplier Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of throwing-supplier Show documentation
Show all versions of throwing-supplier Show documentation
Guava cache supplier extension to memoize exceptions, fallback, expiration control.
The newest version!
package com.zeroleak.throwingsupplier;
import com.google.common.base.Supplier;
public abstract class ThrowingSupplier implements Supplier> {
private int attempts = 1;
public abstract T getOrThrow() throws Exception;
@Override
public Throwing get() {
Exception lastError = null;
for (int i = 0; i < attempts; i++) {
try {
T value = getOrThrow();
return new Throwing(value);
} catch (Exception e) {
lastError = e;
}
}
return new Throwing(lastError);
}
public ThrowingSupplier attempts(int attempts) {
this.attempts = attempts;
return this;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy