Class ExceptionFilter


  • public abstract class ExceptionFilter
    extends Object
    Represents exception handling policy that always ends with throwing another exception. Methods of this class apply the exception policy to functional interfaces (usually lambdas) by wrapping them in a try-catch block. Method handle(Throwable) defines the exception handling policy when implemented in derived class. See noexception tutorial.

    Typical usage: ExceptionLogging.log().passing().get(() -> my_throwing_lambda)

    All wrapping methods surround the functional interface with a try-catch block. If the functional interface throws, the exception is caught and passed to handle(Throwable). NullPointerException from null functional interface is caught too. Method handle(Throwable) applies exception handling policy (log, count, propagate, etc.) and throws a replacement or wrapping exception. If it returns without throwing any exception, the original exception is rethrown.

    Wrapping methods for all standard functional interfaces are provided. Simple interfaces have short method names like runnable(Runnable) or supplier(Supplier). Interfaces with longer names have methods that follow fromX naming pattern, for example fromUnaryOperator(UnaryOperator). Parameterless functional interfaces can be called directly by methods run(Runnable), get(Supplier), and the various getAsX variants.

    See Also:
    Tutorial, handle(Throwable), ExceptionHandler.passing(), ExceptionHandler, CheckedExceptionHandler