Skip to content

Instantly share code, notes, and snippets.

@mchmielarz
Created December 17, 2018 21:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mchmielarz/77e317962414358c82cd09c72e2f340a to your computer and use it in GitHub Desktop.
Save mchmielarz/77e317962414358c82cd09c72e2f340a to your computer and use it in GitHub Desktop.
Chained onFailure call
Try.of(this::computation)
.onFailure(exc -> log.error("Computation failed!", exc))
  .andThen(this::storeInDb)
  .onFailure(exc -> log.error("Storing in database failed!", exc))
  .andThen(this::sendEmail)
  .onFailure(exc -> log.error("Email sending failed!", exc))
  .onSuccess(value -> log.info("Value computed, stored in db and sent in email"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment