Skip to content

Instantly share code, notes, and snippets.

@obatiuk
Created May 31, 2023 20:31
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 obatiuk/c42f1648780efa8af0431e30a713a714 to your computer and use it in GitHub Desktop.
Save obatiuk/c42f1648780efa8af0431e30a713a714 to your computer and use it in GitHub Desktop.
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