Class FilterExceptions
-
- All Implemented Interfaces:
public class FilterExceptionsA collection of helper methods for limiting which checked exceptions can escape a block of code.
The specified exceptions, if any, will propagate normally, as will Errors and s. Any other exceptions will be wrapped in AssertionError and their unexpected-ness will be logged.
Intended for use with
nativemethods, where exception specs aren't enforced.PublicKey key = FilterExceptions.filterExceptions( InvalidKeyException.class, () -> Native.doSomethingThatMightFail(keyBytes));
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public interfaceFilterExceptions.ThrowingNativeOperationA "functional interface" for an operation that returns an object and can throw.
public interfaceFilterExceptions.ThrowingNativeIntOperationA "functional interface" for an operation that returns an
intand can throw.public interfaceFilterExceptions.ThrowingNativeLongOperationA "functional interface" for an operation that returns a
longand can throw.public interfaceFilterExceptions.ThrowingNativeVoidOperationA "functional interface" for an operation that has no result but can throw.
public interfaceFilterExceptions.ThrowingLongFunctionA "functional interface" for an operation that maps a
longvalue to an object and can throw.public interfaceFilterExceptions.ThrowingLongConsumerA "functional interface" for an operation that accepts a
longvalue, has no result, and can throw.
-
Constructor Summary
Constructors Constructor Description FilterExceptions()
-
Method Summary
Modifier and Type Method Description static <R> RfilterExceptions(FilterExceptions.ThrowingNativeOperation<R> f)Tries to run f, wrapping all checked exceptions in AssertionError.static intfilterExceptions(FilterExceptions.ThrowingNativeIntOperation f)Tries to run f, wrapping all checked exceptions in AssertionError.static longfilterExceptions(FilterExceptions.ThrowingNativeLongOperation f)Tries to run f, wrapping all checked exceptions in AssertionError.static voidfilterExceptions(FilterExceptions.ThrowingNativeVoidOperation f)Tries to run f, wrapping all checked exceptions in AssertionError.static <R, E extends Exception> RfilterExceptions(Class<E> e1, FilterExceptions.ThrowingNativeOperation<R> f)Tries to run f, wrapping all checked exceptions besides subclasses ofEin AssertionError.static <E extends Exception> longfilterExceptions(Class<E> e1, FilterExceptions.ThrowingNativeLongOperation f)Tries to run f, wrapping all checked exceptions besides subclasses ofEin AssertionError.static <E extends Exception> voidfilterExceptions(Class<E> e1, FilterExceptions.ThrowingNativeVoidOperation f)Tries to run f, wrapping all checked exceptions besides subclasses ofEin AssertionError.static <R, E1 extends Exception, E2 extends Exception> RfilterExceptions(Class<E1> e1, Class<E2> e2, FilterExceptions.ThrowingNativeOperation<R> f)Tries to run f, wrapping all checked exceptions besides subclasses ofE1andE2in AssertionError.static <E1 extends Exception, E2 extends Exception> voidfilterExceptions(Class<E1> e1, Class<E2> e2, FilterExceptions.ThrowingNativeVoidOperation f)Tries to run f, wrapping all checked exceptions besides subclasses ofE1andE2in AssertionError.static <E1 extends Exception, E2 extends Exception, E3 extends Exception> longfilterExceptions(Class<E1> e1, Class<E2> e2, Class<E3> e3, FilterExceptions.ThrowingNativeLongOperation f)Tries to run f, wrapping all checked exceptions besides subclasses ofE1,E2, andE3in AssertionError.static <R, E1 extends Exception, E2 extends Exception, E3 extends Exception, E4 extends Exception> RfilterExceptions(Class<E1> e1, Class<E2> e2, Class<E3> e3, Class<E4> e4, FilterExceptions.ThrowingNativeOperation<R> f)Tries to run f, wrapping all checked exceptions besides subclasses ofE1,E2,E3, andE4in AssertionError.static <E1 extends Exception, E2 extends Exception, E3 extends Exception, E4 extends Exception> longfilterExceptions(Class<E1> e1, Class<E2> e2, Class<E3> e3, Class<E4> e4, FilterExceptions.ThrowingNativeLongOperation f)Tries to run f, wrapping all checked exceptions besides subclasses ofE1,E2,E3, andE4in AssertionError.static <R, E1 extends Exception, E2 extends Exception, E3 extends Exception, E4 extends Exception, E5 extends Exception> RfilterExceptions(Class<E1> e1, Class<E2> e2, Class<E3> e3, Class<E4> e4, Class<E5> e5, FilterExceptions.ThrowingNativeOperation<R> f)Tries to run f, wrapping all checked exceptions besides subclasses ofE1,E2,E3,E4, andE5in AssertionError.-
-
Method Detail
-
filterExceptions
static <R> R filterExceptions(FilterExceptions.ThrowingNativeOperation<R> f)
Tries to run
f, wrapping all checked exceptions in AssertionError.See the class-level documentation for more details.
-
filterExceptions
static int filterExceptions(FilterExceptions.ThrowingNativeIntOperation f)
Tries to run
f, wrapping all checked exceptions in AssertionError.See the class-level documentation for more details.
-
filterExceptions
static long filterExceptions(FilterExceptions.ThrowingNativeLongOperation f)
Tries to run
f, wrapping all checked exceptions in AssertionError.See the class-level documentation for more details.
-
filterExceptions
static void filterExceptions(FilterExceptions.ThrowingNativeVoidOperation f)
Tries to run
f, wrapping all checked exceptions in AssertionError.See the class-level documentation for more details.
-
filterExceptions
static <R, E extends Exception> R filterExceptions(Class<E> e1, FilterExceptions.ThrowingNativeOperation<R> f)
Tries to run
f, wrapping all checked exceptions besides subclasses ofEin AssertionError.See the class-level documentation for more details.
-
filterExceptions
static <E extends Exception> long filterExceptions(Class<E> e1, FilterExceptions.ThrowingNativeLongOperation f)
Tries to run
f, wrapping all checked exceptions besides subclasses ofEin AssertionError.See the class-level documentation for more details.
-
filterExceptions
static <E extends Exception> void filterExceptions(Class<E> e1, FilterExceptions.ThrowingNativeVoidOperation f)
Tries to run
f, wrapping all checked exceptions besides subclasses ofEin AssertionError.See the class-level documentation for more details.
-
filterExceptions
static <R, E1 extends Exception, E2 extends Exception> R filterExceptions(Class<E1> e1, Class<E2> e2, FilterExceptions.ThrowingNativeOperation<R> f)
Tries to run
f, wrapping all checked exceptions besides subclasses ofE1andE2in AssertionError.See the class-level documentation for more details.
-
filterExceptions
static <E1 extends Exception, E2 extends Exception> void filterExceptions(Class<E1> e1, Class<E2> e2, FilterExceptions.ThrowingNativeVoidOperation f)
Tries to run
f, wrapping all checked exceptions besides subclasses ofE1andE2in AssertionError.See the class-level documentation for more details.
-
filterExceptions
static <E1 extends Exception, E2 extends Exception, E3 extends Exception> long filterExceptions(Class<E1> e1, Class<E2> e2, Class<E3> e3, FilterExceptions.ThrowingNativeLongOperation f)
Tries to run
f, wrapping all checked exceptions besides subclasses ofE1,E2, andE3in AssertionError.See the class-level documentation for more details.
-
filterExceptions
static <R, E1 extends Exception, E2 extends Exception, E3 extends Exception, E4 extends Exception> R filterExceptions(Class<E1> e1, Class<E2> e2, Class<E3> e3, Class<E4> e4, FilterExceptions.ThrowingNativeOperation<R> f)
Tries to run
f, wrapping all checked exceptions besides subclasses ofE1,E2,E3, andE4in AssertionError.See the class-level documentation for more details.
-
filterExceptions
static <E1 extends Exception, E2 extends Exception, E3 extends Exception, E4 extends Exception> long filterExceptions(Class<E1> e1, Class<E2> e2, Class<E3> e3, Class<E4> e4, FilterExceptions.ThrowingNativeLongOperation f)
Tries to run
f, wrapping all checked exceptions besides subclasses ofE1,E2,E3, andE4in AssertionError.See the class-level documentation for more details.
-
filterExceptions
static <R, E1 extends Exception, E2 extends Exception, E3 extends Exception, E4 extends Exception, E5 extends Exception> R filterExceptions(Class<E1> e1, Class<E2> e2, Class<E3> e3, Class<E4> e4, Class<E5> e5, FilterExceptions.ThrowingNativeOperation<R> f)
Tries to run
f, wrapping all checked exceptions besides subclasses ofE1,E2,E3,E4, andE5in AssertionError.See the class-level documentation for more details.
-
-
-
-