Watch
2
0
Fork
You've already forked jdeferthrow
0
Defer and combine exceptions
  • Java 99.2%
  • CSS 0.8%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-07-31 18:42:54 +01:00
.forgejo Update workflows. 2026-07-31 18:42:54 +01:00
com.io7m.jdeferthrow.core Begin next development iteration. 2024-05-05 18:14:12 +00:00
com.io7m.jdeferthrow.tests Use junit BOM. 2024-10-26 12:55:22 +00:00
src/site/resources Update site metadata. 2025-08-09 15:06:53 +00:00
.gitignore Update .gitignore. 2024-05-07 16:01:43 +00:00
doc7m-books.json Add doc7m-books.json 2026-07-31 18:36:45 +01:00
pom.xml Migrate project. 2026-06-27 09:49:53 +01:00
README-CHANGES.xml Mark release 1.3.0 2024-05-05 18:14:05 +00:00
README-LICENSE.txt Update LICENSE 2023-08-13 21:07:28 +00:00
README.in Migrate project. 2026-06-27 09:49:53 +01:00
README.in.md Add README base 2022-10-01 10:11:19 +00:00
README.md Migrate project. 2026-06-27 09:49:53 +01:00

jdeferthrow

Maven Central Maven Central (snapshot) Java Version

com.io7m.jdeferthrow

Description

The jdeferthrow package implements a trivial API for combining multiple exceptions over a series of statements.

Usage

final var tracker = new ExceptionTracker<IOException>();

try {
  doIO1();
} catch (IOException e1) {
  tracker.addException(e1);
}

try {
  doIO2();
} catch (IOException e2) {
  tracker.addException(e2);
}

try {
  doIO3();
} catch (IOException e3) {
  tracker.addException(e3);
}

tracker.throwIfNecessary();

The above code will execute doIO1, doIO2, and doIO3, catching each exception if any are raised. The throwIfNecessary method will throw whichever of e1, e2, or e3 was caught first, with either of the other two exceptions added to the thrown exception as a suppressed exception.

Concretely, if all of doIO1, doIO2, and doIO3 throw exceptions, the throwIfNecessary method will throw e1 with e2 and e3 added to e1 as suppressed exceptions.

This effectively allows for accumulating exceptions over a range of statements and then throwing an exception at the end that contains all of the exceptions that were thrown.

If addException was not called, throwIfNecessary does nothing.