Skip to content
johnmcclean-aol edited this page Dec 15, 2015 · 4 revisions

Try.withCatch

Execute a code block and handle specified exceptions from micro-transactions

public <Ex extends Throwable> Try<R,Ex> execute(T input,Class<Ex> classes){
		
		return Try.withCatch( ()->transactionTemplate.execute(status-> transaction.apply(input)),classes);
		 
}

# Try.withCatch 2

Execute a code block and handle all exceptions from micro-transactions

public Try<R,Throwable> execute(T input){
		return Try.withCatch( ()->transactionTemplate.execute(status-> transaction.apply(input)));
		 
}

Success.of / Failure.of

Referentially transparent exception handling, from micro-reactive

default<K,V> Try<Boolean,MissingPipeException> enqueue(K key,V value){
		Optional<Adapter<V>> queue = Pipes.get(key);
		queue.map(adapter -> adapter.offer(value));
	
		return queue.isPresent() ? Success.of(true) : 
						Failure.of(new MissingPipeException("Missing queue for key : " + key.toString()));
		
		
	}

Try.runWithCatch

Execute a code block with no success value (Try<Void,Exception).

Try.runWithCatch(this::exceptional,IOException.class)
					.onFail(System.out::println);

//Try[IOEXception]
private void exceptional() throws IOException{
		throw new IOException();
	}
Clone this wiki locally