Package org.aksw.commons.util.exception
Class FinallyRunAll
- java.lang.Object
-
- org.aksw.commons.util.exception.FinallyRunAll
-
- All Implemented Interfaces:
Runnable
public class FinallyRunAll extends Object implements Runnable
Force all actions in a list to run. Usage:
This is more succinct than nested finally blocks such as:FinallyAll.run( () -> action1(), () -> action2(), () -> actionN() );{@code try { action1(); } catch (Exception e) { throw new RuntimeException(e); } finally { try { action2(); } catch ... { try { actionN(); } catch ... { } } }
-
-
Field Summary
Fields Modifier and Type Field Description protected List<ThrowingRunnable>actions
-
Constructor Summary
Constructors Constructor Description FinallyRunAll()FinallyRunAll(List<ThrowingRunnable> actions)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(Runnable runnable)voidadd(Callable<?> callable)voidaddThrowing(ThrowingRunnable action)static FinallyRunAllcreate()voidrun()static voidrun(ThrowingRunnable... actions)protected voidrunAction(int index)
-
-
-
Field Detail
-
actions
protected List<ThrowingRunnable> actions
-
-
Constructor Detail
-
FinallyRunAll
public FinallyRunAll()
-
FinallyRunAll
public FinallyRunAll(List<ThrowingRunnable> actions)
-
-
Method Detail
-
create
public static FinallyRunAll create()
-
addThrowing
public void addThrowing(ThrowingRunnable action)
-
add
public void add(Callable<?> callable)
-
add
public void add(Runnable runnable)
-
runAction
protected void runAction(int index)
-
run
public static void run(ThrowingRunnable... actions)
-
-