Created
September 13, 2019 14:00
-
-
Save tmanOC/370ff69150faef3382b4f75f40a256d2 to your computer and use it in GitHub Desktop.
Java exception utility
This file contains 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
public class ExceptionUtil { | |
public interface MayThrow<R>{ | |
public R method() throws Exception; | |
} | |
public static <T> T tryBlock(MayThrow<T> throwing) { | |
try{ | |
T obj = throwing.method(); | |
return obj; | |
} catch(Exception e) { | |
System.out.println(e.getLocalizedMessage()); | |
return null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment