net.sf.staccatocommons.io.internal
Class Handle

java.lang.Object
  extended by net.sf.staccatocommons.io.internal.Handle

public class Handle
extends Object

Utility class for handling exception in Callables

Author:
flbulgarelli

Method Summary
static
<ExceptionType extends Exception,R>
R
throwing(Callable<R> thunk, Class<ExceptionType> exceptionClass)
          Sends Callable.call() to the given callable, throwing any exception of type exceptionClass - including subtypes - , and softening any exception of any other type.
static
<ExceptionType1 extends Exception,ExceptionType2 extends Exception,R>
R
throwing(Callable<R> thunk, Class<ExceptionType1> exceptionClass1, Class<ExceptionType2> exceptionClass2)
          Sends Callable.call() to the given callable, throwing any exception of type exceptionClass1 or exceptionClass2 - including subtypes - , and softening any exception of any other type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

throwing

public static <ExceptionType extends Exception,R> R throwing(Callable<R> thunk,
                                                             Class<ExceptionType> exceptionClass)
                  throws ExceptionType extends Exception
Sends Callable.call() to the given callable, throwing any exception of type exceptionClass - including subtypes - , and softening any exception of any other type.

Type Parameters:
ExceptionType -
Parameters:
exceptionClass - the type of exception that will be thrown without being soften. This class should correspond to a checked exception type. Otherwise, this method would not provide any benefit over sending call() directly.
Returns:
the result of evaluating Callable.call()
Throws:
RuntimeException - if any exception of type different from exceptionClass is thrown while evaluating Callable.call().
ExceptionType extends Exception

throwing

public static <ExceptionType1 extends Exception,ExceptionType2 extends Exception,R> R throwing(Callable<R> thunk,
                                                                                               Class<ExceptionType1> exceptionClass1,
                                                                                               Class<ExceptionType2> exceptionClass2)
                  throws ExceptionType1 extends Exception,
                         ExceptionType2 extends Exception
Sends Callable.call() to the given callable, throwing any exception of type exceptionClass1 or exceptionClass2 - including subtypes - , and softening any exception of any other type.

Type Parameters:
ExceptionType1 -
ExceptionType2 -
Parameters:
exceptionClass1 - one of the two types of exceptions that will be thrown without being soften. This class should correspond to a checked exception type. Otherwise, this method would not provide any benefit over sending call() directly.
exceptionClass2 - the second type of exception that will be thrown without being soften. Same restrictions of exceptionClass1 apply
Returns:
the result of evaluating Callable.call()
Throws:
RuntimeException - if any exception of type different from exceptionClass1 or exceptionClass2 is thrown while evaluating Callable.call().
ExceptionType1 extends Exception


Copyright © 2010-2012 StaccatoCommons. All Rights Reserved.