org.apache.commons.collections4.functors
Class CatchAndRethrowClosure<E>

java.lang.Object
  extended by org.apache.commons.collections4.functors.CatchAndRethrowClosure<E>
All Implemented Interfaces:
Closure<E>

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 strList = // some list
 try {
     CollctionUtils.forAllDo(strList, writer);
 } catch (FunctorException ex) {
     Throwable originalError = ex.getCause();
     // handle error
 }
 

Since:
4.0
Version:
$Id: CatchAndRethrowClosure.java 1477798 2013-04-30 19:49:02Z tn $

Constructor Summary
CatchAndRethrowClosure()
           
 
Method Summary
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CatchAndRethrowClosure

public CatchAndRethrowClosure()
Method Detail

execute

public void execute(E input)
Execute this closure on the specified input object.

Specified by:
execute in interface Closure<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 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.


Copyright © 2001–2013 The Apache Software Foundation. All rights reserved.