class SafeFuture extends CompletableFuture<T> {

  public SafeFuture<T> catchAndRethrow(final Consumer<Throwable> onError) {
    return exceptionallyCompose(
        error -> {
          onError.accept(error);
          return failedFuture(error);
        });
  }

}