Class CatchAndRethrowClosure<E>
- java.lang.Object
-
- org.apache.commons.collections4.functors.CatchAndRethrowClosure<E>
-
- All Implemented Interfaces:
Closure<E>
public abstract class CatchAndRethrowClosure<E> extends java.lang.Object implements Closure<E>
Closurethat catches any checked exception and re-throws it as aFunctorExceptionruntime exception. Example usage:// Create a catch and re-throw closure via anonymous subclass CatchAndRethrowClosure<String> writer = new ThrowingClosure() { private java.io.Writer out = // some writer protected void executeAndThrow(String input) throws IOException { out.write(input); // throwing of IOException allowed } }; // use catch and re-throw closure java.util.List<String> strList = // some list try { CollectionUtils.forAllDo(strList, writer); } catch (FunctorException ex) { Throwable originalError = ex.getCause(); // handle error }- Since:
- 4.0
-
-
Constructor Summary
Constructors Constructor Description CatchAndRethrowClosure()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidexecute(E input)Execute this closure on the specified input object.protected abstract voidexecuteAndThrow(E input)Execute this closure on the specified input object.
-
-
-
Method Detail
-
execute
public void execute(E input)
Execute this closure on the specified input object.- Specified by:
executein interfaceClosure<E>- Parameters:
input- the input to execute on- Throws:
FunctorException- (runtime) if the closure execution resulted in a checked exception.
-
executeAndThrow
protected abstract void executeAndThrow(E input) throws java.lang.Throwable
Execute this closure on the specified input object.- Parameters:
input- the input to execute on- Throws:
java.lang.Throwable- if the closure execution resulted in a checked exception.
-
-