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
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(); |
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
Double number = ExceptionUtil.tryBlock(() -> Double.valueOf(numberAsString)) |
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) { |
NewerOlder