Skip to content

Instantly share code, notes, and snippets.

@mikhasd
Created January 11, 2013 18:50
Show Gist options
  • Save mikhasd/4512987 to your computer and use it in GitHub Desktop.
Save mikhasd/4512987 to your computer and use it in GitHub Desktop.
Hides checked exception
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