net.sf.qualitytest.blueprint
Class SafeInvoke

java.lang.Object
  extended by net.sf.qualitytest.blueprint.SafeInvoke

public final class SafeInvoke
extends Object

Invoke a method or execute code without having to care for checked (and unchecked) exceptions. All exceptions can be converted to a defined runtime exception.

Author:
Dominik Seichter

Nested Class Summary
static interface SafeInvoke.ExceptionRunnable<T>
          A runnable which is allowed to throw any kind of exceptions.
 
Method Summary
static
<T> T
invoke(SafeInvoke.ExceptionRunnable<T> runnable, Class<? extends RuntimeException> exceptionClass)
          Safely invoke a method on an object without having to care about checked exceptions.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

invoke

public static <T> T invoke(@Nonnull
                           SafeInvoke.ExceptionRunnable<T> runnable,
                           @Nonnull
                           Class<? extends RuntimeException> exceptionClass)
Safely invoke a method on an object without having to care about checked exceptions. The runnable is executed and every exception is converted into a BlueprintException.

Parameters:
runnable - An ExceptionRunnable
exceptionClass - The kind of exception that should be thrown. If the thrown exception is not a subclass of this class, a new instance is created
Throws:
Throwable
BlueprintException - in case of any error


Copyright © 2012-2013. All Rights Reserved.