Last active
July 20, 2018 11:09
-
-
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
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 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