public class Exceptions
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static interface |
Exceptions.RunnableWithException |
| Constructor and Description |
|---|
Exceptions() |
| Modifier and Type | Method and Description |
|---|---|
static java.lang.String |
renderStackTrace(java.lang.Throwable t) |
static void |
throwUnchecked(java.lang.Throwable ex) |
static <T> T |
throwUnchecked(java.lang.Throwable ex,
java.lang.Class<T> returnType)
Because this method throws an unchecked exception, when it is called in a method with a return
type the compiler does not know the method is exiting, requiring a further line to return null
or throw an unchecked exception directly.
|
static <T> T |
uncheck(java.util.concurrent.Callable<T> work,
java.lang.Class<T> returnType) |
static void |
uncheck(Exceptions.RunnableWithException work) |
public static <T> T throwUnchecked(java.lang.Throwable ex,
java.lang.Class<T> returnType)
String someMethod() {
try {
somethingThatThrowsException();
} catch (Exception e) {
return throwUnchecked(e, String.class); // does not actually return, throws the exception
}
}
ex - The exception that will be thrown, unwrapped and uncheckedreturnType - trick to persuade the compiler that a method returns appropriatelypublic static void throwUnchecked(java.lang.Throwable ex)
ex - The exception that will be thrown, unwrapped and uncheckedpublic static <T> T uncheck(java.util.concurrent.Callable<T> work,
java.lang.Class<T> returnType)
public static void uncheck(Exceptions.RunnableWithException work)
public static java.lang.String renderStackTrace(java.lang.Throwable t)