Class ExceptionSuppressor
- java.lang.Object
 - 
- be.sddevelopment.commons.exceptions.ExceptionSuppressor
 
 
- 
public final class ExceptionSuppressor extends Object
When using functional programming techniques in java 8+, a common issue is the inability to chain operations using method references if those called methods throw a checked exception.
This class is meant to suppress these checked exceptions.
It can also be used to write your exception handling in a more fluent way, and to facilitate designs based on using Unchecked Exceptions.Example usage
References
- Since:
 - 1.0.0
 - Version:
 - 1.0.0
 - Author:
 - Stijn Dejongh
 
 
- 
- 
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T,R>
Function<T,R>ignore(be.sddevelopment.commons.exceptions.FallibleFunction<T,R> toWrap)Wrapper to be used when you wish to ignore an exception.static <T,R>
Function<T,Optional<R>>ignoreAsOptional(be.sddevelopment.commons.exceptions.FallibleFunction<T,R> toWrap)Wrapper to be used when you wish to ignore an exception, and retrieve the result as an Optional.static <T,R>
Function<T,R>uncheck(be.sddevelopment.commons.exceptions.FallibleFunction<T,R> toWrap)Wrapper to use to convert an exception from a checked type to an unchecked type. 
 - 
 
- 
- 
Method Detail
- 
ignore
public static <T,R> Function<T,R> ignore(be.sddevelopment.commons.exceptions.FallibleFunction<T,R> toWrap)
Wrapper to be used when you wish to ignore an exception.- Type Parameters:
 T- The input type of the wrapped functionR- The return type of the wrapped function- Parameters:
 toWrap- The function call to wrap. Exceptions thrown by this function will be ignored.- Returns:
 - The result of the wrapped function in the happy flow case. The method will return null in case an exception occured.
 
 
- 
ignoreAsOptional
public static <T,R> Function<T,Optional<R>> ignoreAsOptional(be.sddevelopment.commons.exceptions.FallibleFunction<T,R> toWrap)
Wrapper to be used when you wish to ignore an exception, and retrieve the result as an Optional.- Type Parameters:
 T- The input type of the wrapped functionR- The return type of the wrapped function- Parameters:
 toWrap- The function call to wrap. Exceptions thrown by this function will be ignored.- Returns:
 - The result of the wrapped function in the happy flow case. The method will return an
                empty 
Optionalin case an exception occured. 
 
- 
uncheck
public static <T,R> Function<T,R> uncheck(be.sddevelopment.commons.exceptions.FallibleFunction<T,R> toWrap)
Wrapper to use to convert an exception from a checked type to an unchecked type. This method will throw exceptions of theWrappedExceptiontype.- Type Parameters:
 T- The input type of the wrapped functionR- The return type of the wrapped function- Parameters:
 toWrap- The function call to wrap. Exceptions thrown by this function will be converted to runtime exceptions.- Returns:
 
 
 - 
 
 -