@Test public void test() throws Exception { final FileNotFoundException fnfe = new FileNotFoundException(); try { ExceptionUtil.rethrow(fnfe, IOException.class); fail(); } catch (final IOException e) { assertTrue("we won !?!", true); } ExceptionUtil.rethrow(fnfe, ClassNotFoundException.class); try { ExceptionUtil.rethrow(fnfe, FileNotFoundException.class); fail(); } catch (final FileNotFoundException e) { assertTrue("we won !?!", true); } }
public static <T extends Throwable> void rethrow(final Throwable t, final Class<T> clz) throws T { if (clz.isAssignableFrom(t.getClass())) { throw (T) t; } }
ExceptionUtil { public static <T extends Throwable> void rethrow(final Throwable t, final Class<T> clz) throws T { if (clz.isAssignableFrom(t.getClass())) { throw (T) t; } } }
ExceptionUtil { public static <T extends Throwable> void rethrow(final Throwable t, final Class<T> clz) throws T { if (clz.isAssignableFrom(t.getClass())) { throw (T) t; } }  }
ExceptionUtil { public static <T extends Throwable> void rethrow(final Throwable t, final Class<T> clz) throws T { if (clz.isAssignableFrom(t.getClass())) { throw (T) t; } }  static String toString(final Throwable th); static String toString(final Throwable th, final boolean printStack); static void rethrowRuntime(final Throwable t); static void rethrow(final Throwable t, final Class<T> clz); }
ExceptionUtil { public static <T extends Throwable> void rethrow(final Throwable t, final Class<T> clz) throws T { if (clz.isAssignableFrom(t.getClass())) { throw (T) t; } }  static String toString(final Throwable th); static String toString(final Throwable th, final boolean printStack); static void rethrowRuntime(final Throwable t); static void rethrow(final Throwable t, final Class<T> clz);  }