Package com.yahoo.yolean
Class Exceptions
- java.lang.Object
-
- com.yahoo.yolean.Exceptions
-
public class Exceptions extends java.lang.Object
Helper methods for handling exceptions- Author:
- bratseth
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
Exceptions.RunnableThrowingIOException
static interface
Exceptions.SupplierThrowingIOException<T>
-
Constructor Summary
Constructors Constructor Description Exceptions()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T extends java.lang.Throwable>
java.util.Optional<T>findCause(java.lang.Throwable t, java.lang.Class<T> clazz)
Returns the first cause or the given throwable that is an instance ofclazz
static java.lang.String
toMessageString(java.lang.Throwable t)
Returns a user friendly error message string which includes information from all nested exceptions.static void
uncheck(Exceptions.RunnableThrowingIOException runnable)
Wraps any IOException thrown from a runnable in an UncheckedIOException.static void
uncheck(Exceptions.RunnableThrowingIOException runnable, java.lang.String format, java.lang.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, java.lang.String format, java.lang.String... args)
Wraps any IOException thrown from a supplier in an UncheckedIOException w/message.static <T extends java.io.IOException>
voiduncheckAndIgnore(Exceptions.RunnableThrowingIOException runnable, java.lang.Class<T> exceptionToIgnore)
Similar to uncheck(), except an exceptionToIgnore exception is silently ignored.static <R,T extends java.io.IOException>
RuncheckAndIgnore(Exceptions.SupplierThrowingIOException<R> supplier, java.lang.Class<T> exceptionToIgnore)
Similar to uncheck(), except null is returned if exceptionToIgnore is thrown.
-
-
-
Method Detail
-
toMessageString
public static java.lang.String toMessageString(java.lang.Throwable t)
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
public static <T extends java.lang.Throwable> java.util.Optional<T> findCause(java.lang.Throwable t, java.lang.Class<T> clazz)
Returns the first cause or the given throwable that is an instance ofclazz
-
uncheck
public static void uncheck(Exceptions.RunnableThrowingIOException runnable)
Wraps any IOException thrown from a runnable in an UncheckedIOException.
-
uncheck
public static void uncheck(Exceptions.RunnableThrowingIOException runnable, java.lang.String format, java.lang.String... args)
Wraps any IOException thrown from a runnable in an UncheckedIOException w/message.
-
uncheckAndIgnore
public static <T extends java.io.IOException> void uncheckAndIgnore(Exceptions.RunnableThrowingIOException runnable, java.lang.Class<T> exceptionToIgnore)
Similar to uncheck(), except an exceptionToIgnore exception is silently ignored.
-
uncheck
public static <T> T uncheck(Exceptions.SupplierThrowingIOException<T> supplier)
Wraps any IOException thrown from a supplier in an UncheckedIOException.
-
uncheck
public static <T> T uncheck(Exceptions.SupplierThrowingIOException<T> supplier, java.lang.String format, java.lang.String... args)
Wraps any IOException thrown from a supplier in an UncheckedIOException w/message.
-
uncheckAndIgnore
public static <R,T extends java.io.IOException> R uncheckAndIgnore(Exceptions.SupplierThrowingIOException<R> supplier, java.lang.Class<T> exceptionToIgnore)
Similar to uncheck(), except null is returned if exceptionToIgnore is thrown.
-
-