public static interface Try.Init<X extends java.lang.Throwable>
| Modifier and Type | Method and Description |
|---|---|
<V> Try.TryCatch<V,X> |
init(Try.CheckedSupplier<V,X> input)
Initialise a try / catch / finally block
Define the variables to be used within the block.
|
Try<java.lang.Void,X> |
run(Try.CheckedRunnable<X> input)
Run the supplied CheckedRunnable and trap any Exceptions
Return type is Void
|
<V> Try<V,X> |
tryThis(Try.CheckedSupplier<V,X> input)
Run the supplied CheckedSupplier and trap the return value or an Exception
inside a Try
|
<V> Try.TryCatch<V,X> init(Try.CheckedSupplier<V,X> input)
Try.catchExceptions(FileNotFoundException.class,IOException.class)
.init(()->new BufferedReader(new FileReader("file.txt")))
.tryWithResources(this::read);
or
Try t2 = Try.catchExceptions(FileNotFoundException.class,IOException.class)
.init(()->Tuple.tuple(new BufferedReader(new FileReader("file.txt")),new FileReader("hello")))
.tryWithResources(this::read2);
private String read2(Tuple2<BufferedReader,FileReader> res) throws IOException{
String line = res.v1.readLine();
input - Supplier that provides input values to be used in the Try / CatchTry<java.lang.Void,X> run(Try.CheckedRunnable<X> input)
input - CheckedRunnable<V> Try<V,X> tryThis(Try.CheckedSupplier<V,X> input)
input - CheckedSupplier to run