Created
May 31, 2023 20:31
-
-
Save obatiuk/c42f1648780efa8af0431e30a713a714 to your computer and use it in GitHub Desktop.
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
import java.util.concurrent.Callable; | |
public class Unchecked { | |
public static <T> T unchecked(Callable<T> callable) { | |
try { | |
return callable.call(); | |
} catch (Exception ex) { | |
throw new RuntimeException(ex.getMessage(), ex); | |
} | |
} | |
public static void unchecked(RunThrowing runnable) { | |
try { | |
runnable.run(); | |
} catch (Exception ex) { | |
throw new RuntimeException(ex.getMessage(), ex); | |
} | |
} | |
@FunctionalInterface | |
public interface RunThrowing { | |
void run() throws Exception; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment