Last active
December 16, 2017 12:02
-
-
Save golonzovsky/5680169 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package com.test; | |
import java.sql.SQLException; | |
public final class UncheckedThrow { | |
public static void throwUnchecked(final Exception ex){ | |
UncheckedThrow.<RuntimeException>throwsUnchecked(ex); | |
} | |
public static <T extends Exception> void throwsUnchecked(Exception toThrow) throws T{ | |
throw ( T ) toThrow; | |
} | |
public static void main(String[] args) { | |
throwUnchecked(new SQLException()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
see explanation http://www.gamlor.info/wordpress/2010/02/throwing-checked-excpetions-like-unchecked-exceptions-in-java/