Skip to content

Instantly share code, notes, and snippets.

import java.util.Optional;
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();
@tmanOC
tmanOC / UsingExceptionUtil.java
Created September 16, 2019 09:26
Using Exception Util
Double number = ExceptionUtil.tryBlock(() -> Double.valueOf(numberAsString))
@tmanOC
tmanOC / ExceptionUtil.java
Created September 13, 2019 14:00
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) {