Package com.yahoo.yolean
Class Exceptions
java.lang.Object
com.yahoo.yolean.Exceptions
Helper methods for handling exceptions
- Author:
- bratseth
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
static interface
static interface
static interface
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionReturns the first cause or the given throwable that is an instance ofclazz
static RuntimeException
Allows treating checked exceptions as unchecked.static String
Returns a user friendly error message string which includes information from all nested exceptions.static <T,
R> Function<T, R> uncheck
(Exceptions.FunctionThrowingIOException<T, R> function) Wraps any IOException thrown from a function in an UncheckedIOException.static void
Wraps any IOException thrown from a runnable in an UncheckedIOException.static void
uncheck
(Exceptions.RunnableThrowingIOException runnable, String format, String... args) Wraps any IOException thrown from a runnable in an UncheckedIOException w/message.static <T> T
uncheck
(Exceptions.SupplierThrowingIOException<T> supplier) Wraps any IOException thrown from a supplier in an UncheckedIOException.static <T> T
uncheck
(Exceptions.SupplierThrowingIOException<T> supplier, String format, String... args) Wraps any IOException thrown from a supplier in an UncheckedIOException w/message.static <T extends IOException>
voiduncheckAndIgnore
(Exceptions.RunnableThrowingIOException runnable, Class<T> exceptionToIgnore) Similar to uncheck(), except an exceptionToIgnore exception is silently ignored.static <R,
T extends IOException>
RuncheckAndIgnore
(Exceptions.SupplierThrowingIOException<R> supplier, Class<T> exceptionToIgnore) Similar to uncheck(), except null is returned if exceptionToIgnore is thrown.static void
static void
-
Constructor Details
-
Exceptions
public Exceptions()
-
-
Method Details
-
toMessageString
Returns a user friendly error message string which includes information from all nested exceptions.
The form of this string is
e.getMessage(): e.getCause().getMessage(): e.getCause().getCause().getMessage()...
In addition, some heuristics are used to clean up common cases where exception nesting causes bad messages. -
findCause
Returns the first cause or the given throwable that is an instance ofclazz
-
uncheck
Wraps any IOException thrown from a runnable in an UncheckedIOException. -
uncheckInterrupted
-
uncheckInterruptedAndRestoreFlag
public static void uncheckInterruptedAndRestoreFlag(Exceptions.RunnableThrowingInterruptedException runnable) -
uncheck
public static void uncheck(Exceptions.RunnableThrowingIOException runnable, String format, String... args) Wraps any IOException thrown from a runnable in an UncheckedIOException w/message. -
uncheckAndIgnore
public static <T extends IOException> void uncheckAndIgnore(Exceptions.RunnableThrowingIOException runnable, Class<T> exceptionToIgnore) Similar to uncheck(), except an exceptionToIgnore exception is silently ignored. -
uncheck
Wraps any IOException thrown from a function in an UncheckedIOException. -
uncheck
Wraps any IOException thrown from a supplier in an UncheckedIOException. -
uncheck
public static <T> T uncheck(Exceptions.SupplierThrowingIOException<T> supplier, String format, String... args) Wraps any IOException thrown from a supplier in an UncheckedIOException w/message. -
uncheckAndIgnore
public static <R,T extends IOException> R uncheckAndIgnore(Exceptions.SupplierThrowingIOException<R> supplier, Class<T> exceptionToIgnore) Similar to uncheck(), except null is returned if exceptionToIgnore is thrown. -
throwUnchecked
Allows treating checked exceptions as unchecked. Usage: throw throwUnchecked(e); The reason for the return type is to allow writing throw at the call site instead of just calling throwUnchecked. Just calling throwUnchecked means that the java compiler won't know that the statement will throw an exception, and will therefore complain on things such e.g. missing return value.
-