We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
参考 org.apache.commons.lang3.exception.ExceptionUtils 的做法:
org.apache.commons.lang3.exception.ExceptionUtils
public static <R> R rethrow(Throwable throwable) { // claim that the typeErasure invocation throws a RuntimeException return ExceptionUtils.<R, RuntimeException> typeErasure(throwable); } @SuppressWarnings("unchecked") private static <R, T extends Throwable> R typeErasure(Throwable throwable) throws T { throw (T) throwable; }
测试:
public class Main { public static void main(String[] args) { try { throw new Exception(); } catch (Exception e) { ExceptionUtils.rethrow(e); } } }
输出:
Exception in thread "main" java.lang.Exception at com.github.bpazy.test.Main.main(Main.java:14)
The text was updated successfully, but these errors were encountered:
No branches or pull requests
参考
org.apache.commons.lang3.exception.ExceptionUtils
的做法:测试:
输出:
The text was updated successfully, but these errors were encountered: