Created
February 24, 2022 19:41
-
-
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
This file contains hidden or 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
| /** | |
| * 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