/** * Executes the specified task, handling a any exception that occurs. * @param runnable * the task to be executed * @return * the execution result monad */ public static ExecutionResult<Void> runProtected(Runnable runnable) { //NOSONAR try { runnable.run(); //NOSONAR return ExecutionResult.ofVoid(); } catch (Exception e) { return ExecutionResult.ofException(e); } }
/** * Executes the specified task and returnes an execution result. * @param callable * the task to be executed * @param <RESULTTYPE> * the return type of the operation * @return * the execution result monad */ public static <RESULTTYPE> ExecutionResult<RESULTTYPE> runProtected(Callable<RESULTTYPE> callable) { try { return ExecutionResult.ofSuccess(callable.call()); } catch (Exception e) { return ExecutionResult.ofException(e); } }