Skip to content

Instantly share code, notes, and snippets.

@qoomon
Last active July 20, 2018 11:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qoomon/e0c601c3815b6ad108b49923f3b96feb to your computer and use it in GitHub Desktop.
Save qoomon/e0c601c3815b6ad108b49923f3b96feb to your computer and use it in GitHub Desktop.
Java - Throw checked exceptions as a unchecked exceptions see https://github.com/qoomon/unchecked-exceptions-java
public class ExceptionUtils {
/**
* Throws {@code t} as a unchecked exception.
*/
@SuppressWarnings("unchecked")
public static <T extends Throwable> void throwUnchecked(Throwable t) throws T {
throw (T) t;
}
public static void main(String[] args) {
Exception e = new Exception("Boom!");
throwUnchecked(e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment