Created
January 11, 2013 18:50
-
-
Save mikhasd/4512987 to your computer and use it in GitHub Desktop.
Hides checked exception
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public final class Throwables { | |
private Throwables() { | |
} | |
/** | |
* Wraps and throws a checked {@link Exception} as a | |
* {@link RuntimeException} | |
* | |
* @param exception | |
* the exception to be wrapped | |
* @throws RuntimeException | |
* throws the wrapped exception | |
*/ | |
public static void propagate(Throwable throwable) throws RuntimeException { | |
if (throwable instanceof RuntimeException) | |
throw (RuntimeException) throwable; | |
Throwables.<RuntimeException> propagate0(throwable); | |
} | |
@SuppressWarnings("unchecked") | |
private static <E extends Exception> void propagate0(Throwable throwable) | |
throws E { | |
throw (E) throwable; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment