-
Notifications
You must be signed in to change notification settings - Fork 51
cyclops invoke dynamic : ExceptionSoftener
johnmcclean-aol edited this page Feb 24, 2016
·
2 revisions
Cyclops has merged with simple-react. Please update your bookmarks (stars :) ) to https://github.com/aol/cyclops-react
All new develpoment on cyclops occurs in cyclops-react. Older modules are still available in maven central.

The cyclops ExceptionSoftener converts CheckedExceptions into UncheckedExceptions without changing the Exception type. That is, your function or method can still throw IOException, it just no longer needs to declare it.
The JDK functional interfaces don't support CheckedExceptions, so the ExceptionSoftener can prove very useful when working with those.
ExceptionSoftener provides softenXXX methods for all Checked Functional interfaces in jOOλ
throw ExceptionSoftener.throwSoftenedException(new IOException("hello"));
throw ExceptionSoftener.throwSoftenedException(new Exception("hello"));
//doesn't need softened, but will still work
throw ExceptionSoftener.throwSoftenedException(new RuntimeException("hello"));
ExceptionSoftener.softenFunction(this::load)
.apply("input");
public String load(String file) throws IOException{
throw new IOException();
}
Supplier<String> supplier = ExceptionSoftener.softenSupplier(this::get);
assertThat(supplier.get(),equalTo("hello"));
private String get() throws IOException{
return "hello";
}