-
-
Save Mufas61/ee22f895b92aeab6b7b1dc9f1cbb49d2 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
| package packt.java9.network.connect; | |
| import java.util.function.Function; | |
| public class RuntTimeExceptionWrapper { | |
| public static <T> T lame(ExceptionalSupplier<T> z) { | |
| try { | |
| return z.apply(); | |
| } catch (Exception e) { | |
| throw new WrapperException(e); | |
| } | |
| } | |
| public static <T, R> Function<T, R> lame(ExceptionalFunction<T, R> f) { | |
| return (T r) -> { | |
| try { | |
| return f.apply(r); | |
| } catch (Exception e) { | |
| throw new WrapperException(e); | |
| } | |
| }; | |
| } | |
| public interface ExceptionalSupplier<T> { | |
| T apply() throws Exception; | |
| } | |
| public interface ExceptionalFunction<T, R> { | |
| R apply(T r) throws Exception; | |
| } | |
| public static class WrapperException extends RuntimeException { | |
| WrapperException(Exception e) { | |
| super(e); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment