Skip to content

Instantly share code, notes, and snippets.

@Pzdrs
Created February 24, 2022 19:41
Show Gist options
  • Select an option

  • Save Pzdrs/29c8af0e018add71d2d2ebaf0c037978 to your computer and use it in GitHub Desktop.

Select an option

Save Pzdrs/29c8af0e018add71d2d2ebaf0c037978 to your computer and use it in GitHub Desktop.
Functional approach to try catch wrapped in a do-while loop to assure an eventual execution of the supplied Runnable
/**
* Functional approach to try catch wrapped in a do-while loop to assure an eventual execution of the supplied Runnable
* @param runnable Try code
* @param onException Catch code
*/
public static void tryCatch(Runnable runnable, Runnable onException) {
boolean done = false;
do {
try {
runnable.run();
done = true;
} catch (Exception exception) {
onException.run();
}
} while (!done);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment