-
Notifications
You must be signed in to change notification settings - Fork 51
Try examples
johnmcclean-aol edited this page Dec 15, 2015
·
4 revisions
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)));
}
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()));
}
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();
}