public abstract class CatchAndRethrowClosure<E> extends Object implements Closure<E>
Closure
that catches any checked exception and re-throws it as a
FunctorException
runtime 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 }
Constructor and Description |
---|
CatchAndRethrowClosure() |
Modifier and Type | Method and Description |
---|---|
void |
execute(E input)
Execute this closure on the specified input object.
|
protected abstract void |
executeAndThrow(E input)
Execute this closure on the specified input object.
|
public CatchAndRethrowClosure()
public void execute(E input)
execute
in interface Closure<E>
input
- the input to execute onFunctorException
- (runtime) if the closure execution resulted in a
checked exception.protected abstract void executeAndThrow(E input) throws Throwable
input
- the input to execute onThrowable
- if the closure execution resulted in a checked
exception.Copyright © 2001–2019 The Apache Software Foundation. All rights reserved.