Skip to content

Instantly share code, notes, and snippets.

@dmikurube
Created February 10, 2022 13:02
Show Gist options
  • Save dmikurube/846fdff9352be30960afab863c68b871 to your computer and use it in GitHub Desktop.
Save dmikurube/846fdff9352be30960afab863c68b871 to your computer and use it in GitHub Desktop.
import java.util.function.Consumer;
final class RuntimeExceptionStacker {
RuntimeExceptionStacker() {
this.exception = null;
}
synchronized RuntimeExceptionStacker add(final RuntimeException ex) {
if (this.exception == null) {
this.exception = ex;
} else {
this.exception.addSuppressed(ex);
}
return this;
}
synchronized void ifPresent(final Consumer<? super RuntimeException> consumer) {
if (this.exception != null) {
consumer.accept(this.exception);
}
}
private RuntimeException exception;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment