Package org.apache.commons.collections4.functors

# Class CatchAndRethrowClosure<T>

java.lang.Object
org.apache.commons.collections4.functors.CatchAndRethrowClosure<T>

Type Parameters:
  `T` - the type of the input to the operation.

All Implemented Interfaces:
  `Consumer<T>`, `Closure<T>`

public abstract class CatchAndRethrowClosure<T> extends Object implements Closure<T>
`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
     }

Since:
  4.0

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `CatchAndRethrowClosure()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `execute(T input)`
  Execute this closure on the specified input object.
  `protected abstract void`
  `executeAndThrow(T input)`
  Execute this closure on the specified input object.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

  ### Methods inherited from interface org.apache.commons.collections4.Closure

  `accept`

  ### Methods inherited from interface java.util.function.Consumer

  `andThen`

- ## Constructor Details

  - ### CatchAndRethrowClosure

    public CatchAndRethrowClosure()

- ## Method Details

  - ### execute

    public void execute(T input)
    Execute this closure on the specified input object.
    Specified by:
      `execute` in interface `Closure<T>`
    Parameters:
      `input` - the input to execute on
    Throws:
      `FunctorException` - (runtime) if the closure execution resulted in a checked exception.

  - ### executeAndThrow

    protected abstract void executeAndThrow(T input) throws Throwable
    Execute this closure on the specified input object.
    Parameters:
      `input` - the input to execute on
    Throws:
      `Throwable` - if the closure execution resulted in a checked exception.