Created
February 10, 2022 13:02
-
-
Save dmikurube/846fdff9352be30960afab863c68b871 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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