N - parameter type of the non throwing interfaceT - parameter type of the throwing interfaceC - parameter type of the chainerpublic abstract class Chainer<N,T extends N,C extends Chainer<N,T,C>> extends Object
If you want to add your own implementation of a chainer, extend this class
and make it implement the throwing version of the interface. The
default set by this package is to wrap the exception into a ThrownByLambdaException when an exception is thrown.
Since all throwing instances extend the non throwing instances by default, this means you can use an instance of a chain as a non throwing instance; for example:
final ToLongFunction<Path>
= Throwing.function(Files::size).orReturn(OL);
Throwing| Modifier and Type | Class and Description |
|---|---|
static class |
Chainer.InstantiationException
Exception thrown when an instance of an exception class cannot be built
|
| Modifier and Type | Method and Description |
|---|---|
protected static RuntimeException |
doSneakyThrow(Throwable throwable) |
abstract N |
fallbackTo(N fallback)
Fall back to a non throwing instance if this instance fails
|
abstract <E extends RuntimeException> |
orThrow(Class<E> exclass)
Rethrow the exception using a custom (unchecked!) exception class if this
throwing instance fails
|
abstract C |
orTryWith(T other)
Try with another throwing instance if the first instance fails
|
protected static <E extends RuntimeException> |
rethrow(Class<E> c,
Throwable t) |
abstract N |
sneakyThrow()
Sneaky throw of the exception thrown by the instance
|
protected Chainer(T throwing)
protected static <E extends RuntimeException> E rethrow(Class<E> c, Throwable t)
protected static RuntimeException doSneakyThrow(Throwable throwable)
public abstract C orTryWith(T other)
other - the other throwing instancepublic abstract <E extends RuntimeException> T orThrow(Class<E> exclass)
Your custom exception class must have a constructor
accepting a single Throwable as an argument.
The original exception thrown will be the cause of the generated exception.
All instances of Error or RuntimeException thrown by
the instance are thrown as is.
E - type parameter of the exception classexclass - the exception classpublic abstract N fallbackTo(N fallback)
fallback - the fallback instancepublic abstract N sneakyThrow()
This code was inspited by the Lombok project.