public final class Exceptions extends Object
| Modifier and Type | Method and Description |
|---|---|
static void |
throwUnchecked(Throwable toThrow) |
static <T> T |
throwUnchecked(Throwable toThrow,
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.
|
public static <T> T throwUnchecked(Throwable toThrow, T returnType)
String someMethod() {
try {
somethingThatThrowsException();
} catch (Exception e) {
return throwUnchecked(e, null); // does not actually return, throws the exception
}
}
toThrow - The throwable that will be thrown, unwrapped and unchecked; must not be nullreturnType - trick to persuade the compiler that a method returns appropriately - always pass null hereNullPointerException - if toThrow is nullpublic static void throwUnchecked(Throwable toThrow)
toThrow - The throwable that will be thrown, unwrapped and unchecked; must not be nullNullPointerException - if toThrow is nullCopyright © 2006-2013. All Rights Reserved.