VM errors ought to be rethrown without being wrapped inside a FunctionException.
49 lines
1.1 KiB
Java
49 lines
1.1 KiB
Java
package info.ebenoit.ebul.func;
|
|
|
|
|
|
/**
|
|
* This interface supports a {@link ToFloatFunction} that can throw checked exceptions. Checked exceptions are
|
|
* transmitted using a {@link FunctionException} runtime exception.
|
|
*
|
|
* @author <a href="mailto:ebenoit@ebenoit.info">E. Benoît</a>
|
|
*/
|
|
@FunctionalInterface
|
|
public interface ThrowingToFloatFunction< T >
|
|
extends ToFloatFunction< T >
|
|
{
|
|
|
|
/**
|
|
* Applies this function to the given argument.
|
|
*
|
|
* @param t
|
|
* the argument
|
|
* @return the result
|
|
* @throws FunctionException
|
|
* if a checked exception occurs
|
|
*/
|
|
@Override
|
|
default float applyAsFloat( final T t )
|
|
{
|
|
try {
|
|
return this.throwingApplyAsFloat( t );
|
|
} catch ( final Error | RuntimeException e ) {
|
|
throw e;
|
|
} catch ( final Throwable e ) {
|
|
throw new FunctionException( e );
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* Applies this function to the given argument.
|
|
*
|
|
* @param t
|
|
* the argument
|
|
* @return the result
|
|
* @throws Throwable
|
|
* any exception
|
|
*/
|
|
public float throwingApplyAsFloat( T t )
|
|
throws Throwable;
|
|
|
|
}
|