Skip to content

Instantly share code, notes, and snippets.

@tmanOC
Created September 13, 2019 14:00
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 tmanOC/370ff69150faef3382b4f75f40a256d2 to your computer and use it in GitHub Desktop.
Save tmanOC/370ff69150faef3382b4f75f40a256d2 to your computer and use it in GitHub Desktop.
Java exception utility
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